Advertisement
dave3009

Sherman

May 4th, 2020
834
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Sub AddAge()
  4. Dim Bday As Date
  5. Dim ofSet As Byte
  6.  
  7.     With Sheet1
  8.        
  9.         Bday = .Range("E7").Value ' get the birth date
  10.        ofSet = IIf(Date < DateSerial(Year(Date), Month(Bday), Day(Bday)), 1, 0) 'offset required if birthday hasn't happened this year
  11.        
  12.         If Bday <> "" Then
  13.             .Range("E8").Value = DateDiff("yyyy", Bday, Date) - ofSet ' write the age in years to the cell
  14.        End If
  15.    
  16.     End With
  17. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement