Clever-Excel-Forum

Normale Version: Datum ausgeben, wenn die Summe erreicht wird // VBA
Du siehst gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Hallo Zusammen, 

Excel soll ein Datum ausgeben, an dem eine angegebene Summe erreicht wurde. 
Ich hab in VBA folgende Funktion hinterlegt:

Public Function ctp(productionDate As Range, raw As Range, order, startDate As Date)
r = 1
dayCount = 0
Sum = 0
For Each cell In raw
If productionDate.Cells(r) = startDate Then
Sum = Sum + cell.Value
If Sum >= order Then
ctp = productionDate.Cells(r)
Exit For
End If
r = r + 1
Next cell
End Function

Es kommt jetzt #WERT Fehler raus... Ich bin echt verzweifelt, sieht jemand hier den Fehler?

Danke sehr!
Hallöchen,

mal ohne Datei und Test - da fehlt doch ein End if
So wird's auch was mit dem Nachbarn....

Code:
Public Function ctp(productionDate As Range, raw As Range, order, startDate As Date)
r = 1
dayCount = 0
Sum = 0
For Each cell In raw
       If productionDate.Cells(r) >= startDate Then Sum = Sum + cell.Value

       If Sum >= order Then
       ctp = Format(productionDate.Cells(r), "dd/mm/yyyy")
       Exit For
       End If
   r = r + 1
Next cell
End Function