[RESOLVED] Calculate Age from Range and Color Cell (VBA)
Hi,
I have a row (or selection) with birth-dates. I need to calculate the age and color the cell/row/text (whatever) where the person is younger then 18. Any change someone knows how to do this? I want to add the code to my existing (automation) code.
Thanks in advance.
Re: Calculate Age from Range and Color Cell (VBA)
Try something like this:
Code:
Sub bDates()
Dim i As Integer
For i = 1 To 7 'my sample data is in column A, rows 1 to 7
If Format((Now - Range("a" & i).Value) / 365, 0) > 18 Then
Range("a" & i).Interior.Color = vbRed
End If
Next i
End Sub
Re: Calculate Age from Range and Color Cell (VBA)
That's a nice start, however there seems to be an issue with the age-calculation. Not everyyear has 365 days. Perhaps I'm missing something.
Re: Calculate Age from Range and Color Cell (VBA)
Quote:
Not everyyear has 365 days
use datediff function
Re: Calculate Age from Range and Color Cell (VBA)
Thanks for the tip westconn.