tut dies mit einer Formel ist nicht etwas, ich bin bereit, in Angriff zu nehmen, vielleicht jemand anderes fühlt sich an wie mit dem endlosen Chaos Umgang von verschachtelt if
s.
Stattdessen sollte jedoch eine VBA-Routine ausreichen, die die Anzahl Jahre, Monate, Wochen und Tage zwischen zwei Daten ausspuckt.
Function projectDuration(fromdate As Date, todate As Date) As String
'years
years = DateDiff("yyyy", fromdate, todate)
If years > 1 Then
projectDuration = years & " yrs "
ElseIf years = 1 Then
projectDuration = years & " yr "
End If
'months
months = DateDiff("m", DateAdd("yyyy", years, fromdate), todate)
If months > 1 Then
projectDuration = projectDuration & months & " mths "
ElseIf months = 1 Then
projectDuration = projectDuration & months & " mth "
End If
'weeks
weeks = DateDiff("w", DateAdd("m", months, DateAdd("yyyy", years, fromdate)), todate)
If weeks > 1 Then
projectDuration = projectDuration & weeks & " wks "
ElseIf weeks = 1 Then
projectDuration = projectDuration & weeks & " wk "
End If
'days
days = DateDiff("w", DateAdd("w", weeks, DateAdd("m", months, DateAdd("yyyy", years, fromdate))), todate)
If days > 1 Then
projectDuration = projectDuration & days & " days"
ElseIf days = 1 Then
projectDuration = projectDuration & days & " day"
End If
End Function
Dies ist ein UDF. Stecken Sie es einfach in ein neues Modul in Ihrem VBE und dann können Sie diese Formel in Ihrem Arbeitsblatt verwenden. wenn Sie die folgenden in Ihrem Blatt Zum Beispiel haben:
+---+----------+-----------+
| | A | B |
+---+----------+-----------+
| 1 | 1/1/2016 | 2/16/2016 |
| 2 | | |
+---+----------+-----------+
Sie Formel verwenden:
=projectDuration(A1,B1)
Und es wird 1 mth 2 wks 1 day
ausspucken.
Was ist Ihre Frage? –
Klingt wie 'DateDif' mit etwas extra pizzazz. Siehe [hier] (https://support.office.com/de-de/article/Calculate-the-difference-between-two-dates-8235e7c9-b430-44ca-9425-46100a162f38) – JNevill
Und wenn @JNevill sagt ' pizzazz 'er meint eine Menge von IF() Statements, um mit allen Eventualitäten umzugehen. –