Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Sub AddAge()
- Dim Bday As Date
- Dim ofSet As Byte
- With Sheet1
- Bday = .Range("E7").Value ' get the birth date
- ofSet = IIf(Date < DateSerial(Year(Date), Month(Bday), Day(Bday)), 1, 0) 'offset required if birthday hasn't happened this year
- If Bday <> "" Then
- .Range("E8").Value = DateDiff("yyyy", Bday, Date) - ofSet ' write the age in years to the cell
- End If
- End With
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement