der nachstehende Code bewirkt, dass eine Summe in Textbox9 ggfs. über mehrere Jahre aufgeteilt wird. Also, z.B. v. 01.11.09-31.01.10 somit 2 Monate in 2009 anteilig und 1 Monat in 2010. Könnte der Code evtl. so abgeändert werden, dass die Aufteilung ins nächste Jahr nicht erst am 01.01. des Jahres vorgenommen wird, sondern schon ab 01.12. des Jahres? Der Dezember somit schon dem neuen Jahr zugeschlagen wird? - Schon jetzt recht herzlichen Dank für die Rückmeldungen.
Gruß - Wolfgang
Private Sub Jahresaufteilung()
Dim i As Integer
Dim vonDatum As Date, bisDatum As Date
Dim SchnittTag As Double
With Application.WorksheetFunction
If IsDate(TextBox5) And IsDate(TextBox6) Then
TextBox25 = .Round((.Max(CDate(TextBox5), CDate(TextBox6)) - .Min(CDate(TextBox5), _
_
CDate(TextBox6)) + 1) / 30.4, 1)
SchnittTag = CDbl(TextBox9) / (CDate(TextBox6) - CDate(TextBox5) + 1)
For i = 0 To Year(CDate(TextBox6)) - Year(CDate(TextBox5))
If i = 0 Then
vonDatum = CDate(TextBox5)
bisDatum = .Min(DateSerial(Year(CDate(TextBox5)), 12, 31), CDate(TextBox6))
Else
vonDatum = .Min(DateSerial(Year(CDate(TextBox5)) + i, 1, 1), CDate(TextBox6))
bisDatum = .Min(DateSerial(Year(CDate(TextBox5)) + i, 12, 31), CDate(TextBox6))
If i > 3 Then bisDatum = CDate(TextBox6)
End If
Me("TextBox" & 13 + i) = .Round(SchnittTag * (CDbl(bisDatum) - CDbl(vonDatum) + 1), _
_
2)
'Me("TextBox" & 13 + i) = SchnittTag * (CDbl(bisDatum) - CDbl(vonDatum) + 1)
If i 2 Then Exit For
Next i
Else
TextBox25 = ""
End If
End With
End Sub