AW: Datumsproblem
20.11.2003 11:13:50
Nayus
Hi,
für eine einfache Formel ist der Sachverhalt m. E. zu kompliziert.
Anbei eine UDF, die Du dann in Deiner Mappe verwenden kannst.
Die benötigten Parameter stehen im Tabellenblatt und werden übergeben
=CalcRent(A1;B1;C1;A2;B2;C2;A4;B4)
To do:
Im VBA-Editor ein neues Modul anlegen und nachfolgenden Code einfügen
Public Function CalcRent(pFare1Start As Date, pFare1End As Date, pFare1 As Double, fFare2Start As Date, pFare2End As Date, pFare2 As Double, pStart As Date, pEnd As Date) As Double
Application.Volatile
Dim l_ret As Double, l_buff As Double
l_ret = 0
l_buff = 0
If Year(pStart) = Year(pEnd) Then
' innerhalb eines Jahres
For i = Month(pStart) To Month(pEnd)
l_buff = getMonthlyFare(pFare1Start, pFare1End, pFare1, pFare2Start, pFare2End, pFare2, DateSerial(Year(pStart), i, 1))
l_ret = l_ret + l_buff
Next i
ElseIf Year(pStart) = Year(pEnd) - 1 Then
' über den Jahreswechsel hinweg
For j = Month(pStart) To 12
l_buff = getMonthlyFare(pFare1Start, pFare1End, pFare1, pFare2Start, pFare2End, pFare2, DateSerial(Year(pStart), j, 1))
l_ret = l_ret + l_buff
Next j
For k = 1 To Month(pEnd)
l_buff = getMonthlyFare(pFare1Start, pFare1End, pFare1, pFare2Start, pFare2End, pFare2, DateSerial(Year(pEnd), k, 1))
l_ret = l_ret + l_buff
Next k
End If
CalcRent = l_ret
End Function
Private Function getMonthlyFare(ByVal pFare1Start As Date, ByVal pFare1End As Date, ByVal pFare1 As Double, ByVal fFare2Start As Date, ByVal pFare2End As Date, ByVal pFare2 As Double, ByVal pDate As Date) As Double
'Hilfsfunktion für CalcRent
Dim l_ret As Double
If pDate >= pFare1Start And pDate <= pFare1End Then
l_ret = pFare1
ElseIf pDate >= pFare2Start And pDate <= pFare2End Then
l_ret = pFare2
End If
getMonthlyFare = l_ret
End Function
Viel Erfolg,
Nayus