AW: VBA-Geburtstag alter berechnen
17.01.2020 07:15:26
SH95
Hallo Feuerharry,
Global alter(1 To 15), rtage(1 To 15), lzeile
Sub alter_berechnen()
Application.ScreenUpdating = False
lzeile = Sheets(1).Range("B65536").End(xlUp).Row
For i = 3 To lzeile
anzmonate = DateDiff("m", Cells(i, 13), Date)
jahre = Split(anzmonate / 12, ",")
restmonate = anzmonate - (jahre(0) * 12)
resttagedatum = Day(Cells(i, 13)) & "." & Month(Cells(i, 13)) & "." & Year(Date)
resttage = DateDiff("d", Date, resttagedatum)
If Cells(i, 13) "" Then
If resttage > 0 And resttage 1 Then
Cells(i, 14) = jahre(0) & " Jahre" '& restmonate & " Monate"
End If
If restmonate = 1 Then
Cells(i, 14) = jahre(0) & " Jahre" '& restmonate & " Monat"
End If
If restmonate 1 Then
Cells(i, 15) = "noch " & resttage & " Tage"
End If
If resttage = 1 Then
Cells(i, 15) = "noch " & resttage & " Tag"
End If
If resttage = 0 Then
Cells(i, 15) = "heute"
End If
Else
Cells(i, 14).Value = ""
Cells(i, 15).Value = ""
End If
' alter(i) = CLng(Cells(i, 13))
' rtage(i) = resttage
' rtage(i) = resttage
Next
For i = 2 To 500
Columns(i).AutoFit
Next
UserForm1.ClearAll
Application.ScreenUpdating = True
End Sub
So?
Gruß
Stefan