Option Explicit '--piz02 Public Const maxTage = 31, maxProds = 50 '--piz05 Public myCancelled As Boolean '--piz02 Function findProdNum(ByVal was As String) As Long Dim Y As Long, c If was = "" Then findProdNum = 0: Exit Function Y = 0: c = "" While Range("sorte1").Offset(Y, 0) <> was And Y < maxProds Y = Y + 1 Wend ''MsgBox y If Y >= maxProds Then Y = 0 Else Y = Y + 1 findProdNum = Y End Function '--piz02 Sub test_findProdNum() MsgBox findProdNum("Milano") End Sub '--piz03 Function findVorProd() As String Dim x As Long, Y As Long x = ActiveCell.Column: Y = ActiveCell.Row Do Y = Y - 1 Loop Until Cells(Y, x) <> "" Or Y < 4 If Y < 4 Then findVorProd = "" Else findVorProd = Cells(Y, x) End Function '--piz03 Sub test_findVorProd() MsgBox findVorProd End Sub '--piz03 Function findNextProdRow() As Long Dim x As Long, Y As Long x = ActiveCell.Column: Y = ActiveCell.Row + 1 While Cells(Y, x) = "" And Y <= [maxro] Y = Y + 1 Wend findNextProdRow = Y End Function '--piz03 Sub test_findNextProdRow() MsgBox findNextProdRow End Sub '--piz03 Function findProdBeginRow() As Long Dim x As Long, Y As Long x = ActiveCell.Column: Y = ActiveCell.Row While Cells(Y, x) = "" And Y > 5 Y = Y - 1 Wend findProdBeginRow = Y End Function '--piz03 Sub test_findProdBeginRow() MsgBox findProdBeginRow End Sub '--piz03 Function calcQuantperday(Co As Long, PNum) As Double 'Tagesleistung=Ofenkapazität * produktspezifische Intensität calcQuantperday = Cells(2, Co + 1) * [sorte1].Offset([PNum] - 1, 1) End Function '--piz03 Sub test_calcQuantperday() MsgBox calcQuantperday(4, 5) End Sub '--piz03 Function calcDaysforchange(PNum As Long, PreNum As Long) As Double 'Umstelltage aus Tabelle holen, falls wirklich P-Wechsel vorliegt... If PNum <> PreNum And PreNum > 0 Then calcDaysforchange = [change!Nullpunkt].Offset(PreNum, PNum) Else calcDaysforchange = 0 End If End Function '--piz03 Sub test_calcDaysforchange() MsgBox calcDaysforchange(4, 2) End Sub '--piz03 Sub writeQuants(Ro As Long, Co As Long) 'Tagesmengen eintragen - dabei umstellzeit berücksichtigen Dim P As String, Pre As String, PNum As Long, PreNum As Long Dim Days As Long, nextRo As Long Dim Daysforchange As Double, Quantperday As Double, D As Long 'Produktnummern von Produkt und Vorgänger ermitteln... Cells(Ro, Co).Select P = Cells(Ro, Co): PNum = findProdNum(P) Cells(Ro, Co).Select Pre = findVorProd: PreNum = findProdNum(Pre) 'wieviel tage lang ... Cells(Ro, Co).Select nextRo = findNextProdRow '.. also nachfolger suchen um kampagnenende zu kriegen Days = nextRo - Ro 'wieviel produzieren wir pro normalen tag (also ohne umstellverlust) ... Quantperday = main.calcQuantperday(Co, PNum) 'wieviel umstelltage... Daysforchange = main.calcDaysforchange(PNum, PreNum) 'Tagesmengen eintragen... For D = 0 To Days - 1 If Daysforchange > 0 Then If Daysforchange >= 1 Then Cells(Ro + D, Co + 1) = 0 Daysforchange = Daysforchange - 1 ' .. 1 tag weniger zu berücks. Else Cells(Ro + D, Co + 1) = (1 - Daysforchange) * Quantperday Daysforchange = 0 ' nichts mehr zu berücks. - ab nächstem tag volle leistung End If Else Cells(Ro + D, Co + 1) = Quantperday End If Next D End Sub '--piz03 Sub test_writeQuants() Call writeQuants(12, 7) End Sub