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 < 3 Then Me("Label" & 24 + i).Caption = "Jahr " & Year(CDate(TextBox5)) + i
If i > 2 Then Exit For
Next i
Else
TextBox25 = ""
End If
End With
End Sub
bisDatum = .Min(DateSerial(Year(CDate(TextBox5)), 11, 30), CDate(TextBox6))
Else
vonDatum = .Min(DateSerial(Year(CDate(TextBox5)) , 12, 1), CDate(TextBox6))
bisDatum = .Min(DateSerial(Year(CDate(TextBox5)) + i, 11, 30), CDate(TextBox6))
Gruß"habe dabei das vonDatum in bisDatum geändert"
, Du wolltest doch einen Monat vorher anfangen.
bisDatum = .Min(DateSerial(Year(CDate(TextBox5)), 11, 30), CDate(TextBox6))
Else
vonDatum = .Min(DateSerial(Year(CDate(TextBox5)) i-1, 12, 1), CDate(TextBox6))
bisDatum = .Min(DateSerial(Year(CDate(TextBox5)) + i, 11, 30), CDate(TextBox6))
GrußPrivate Sub verteilen()
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(TextBox10) / (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)) ' _
ursprünglich
bisDatum = .Min(DateSerial(Year(CDate(TextBox5)), 11, 30), CDate(TextBox6)) 'von _
Bosko
Else
'vonDatum = .Min(DateSerial(Year(CDate(TextBox5)) + i - 1, 12, 1), CDate(TextBox6)) _
'von Tino
'vonDatum = .Min(DateSerial(Year(CDate(TextBox5)) + i, 1, 1), CDate(TextBox6)) ' _
ursprünglich
'bisDatum = .Min(DateSerial(Year(CDate(TextBox5)) + i, 12, 31), CDate(TextBox6)) ' _
ursprünglich
vonDatum = .Min(DateSerial(Year(CDate(TextBox5)) + i - 1, 12, 1), CDate(TextBox6)) _
'von Bosko
bisDatum = .Min(DateSerial(Year(CDate(TextBox5)) + i, 11, 30), CDate(TextBox6)) ' _
von Bosko
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 < 3 Then Me("Label" & 24 + i).Caption = "Jahr " & Year(CDate(TextBox5)) + i
If i > 2 Then Exit For
Next i
Else
TextBox25 = ""
End If
End With
End Sub
Private Sub verteilen()
Dim daTB5 As Date, daTB6 As Date, intB5j As Integer
Dim SchnittTag As Double, ii As Integer
Dim datVon As Date, datBis As Date
With Application.WorksheetFunction
If IsDate(TextBox5) And IsDate(TextBox6) Then
daTB5 = CDate(TextBox5) + 31
daTB6 = CDate(TextBox6) + 31
intB5j = Year(daTB5)
TextBox25 = .Round((.Max(daTB5, daTB6) - .Min(daTB5, daTB6) + 1) / 30.4, 1)
SchnittTag = CDbl(TextBox10) / (daTB6 - daTB5 + 1) ' Wert pro Tag
For ii = 0 To Year(daTB6) - intB5j
Select Case ii
Case 0
datVon = daTB5
datBis = .Min(DateSerial(intB5j, 12, 31), daTB6)
Case Year(daTB6) - intB5j
datVon = .Min(DateSerial(intB5j, 12, 31), daTB6)
datBis = daTB6
Case Else
datVon = DateSerial(intB5j + ii, 12, 31)
datBis = DateSerial(intB5j + ii, 12, 31)
End Select
Me("TextBox" & 13 + ii) = .Round(SchnittTag * (datBis - datVon + 1), 2)
If ii < 3 Then Me("Label" & 24 + ii).Caption = "Jahr " & intB5j + ii
If ii > 2 Then Exit For ' warum das ?
Next ii
Else
TextBox25 = ""
End If
End With
End Sub
Rückmeldung wäre nett! - Grüße von Erich aus Kamp-Lintfort
Private Sub entschieden() '####### zunächst geht es um diesen Code#####
Dim daTB5 As Date, daTB6 As Date, intB5j As Integer
Dim SchnittTag As Double, ii As Integer
Dim datVon As Date, datBis As Date
With Application.WorksheetFunction
If IsDate(TextBox5) And IsDate(TextBox6) Then
daTB5 = CDate(TextBox5) + 31
daTB6 = CDate(TextBox6) + 32
intB5j = Year(daTB5)
TextBox25 = .Round((.Max(daTB5, daTB6) - .Min(daTB5, daTB6) + 1) / 30.4, 1)
SchnittTag = CDbl(TextBox10) / (daTB6 - daTB5) ' Wert pro Tag
For ii = 0 To Year(daTB6) - intB5j
datVon = .Max(daTB5, DateSerial(intB5j + ii, 1, 1))
datBis = .Min(daTB6, DateSerial(intB5j + ii + 1, 1, 1))
Me("TextBox" & 13 + ii) = .Round(SchnittTag * (datBis - datVon), 2)
If ii < 3 Then Me("Label" & 24 + ii).Caption = "Jahr " & intB5j + ii
' If ii > 2 Then Exit For ' warum das ?
Next ii
Else
TextBox25 = ""
End If
End With
End Sub
Wesentlich ist dabei auch, dass man bei Tages-Zeiträumen immer von Uhrzeit 00:00 ausgehen sollte,