Hello,
Here is another option:
Sub CheckDates()
Dim rng As Range
For Each rng In Intersect([B1:B65536], ActiveSheet.UsedRange)
If VBA.Day(rng.Value) = VBA.Day(Now) Then
MsgBox "Happy Birthday: " & rng.Offset(0, -1).Value, _
vbExclamation, "BirthDay"
Exit For
End If
Next
End Sub
tony_813
Main Topics
Browse All Topics





by: JeggburtPosted on 2006-06-18 at 03:54:46ID: 16929249
The code as follows (you can call this from your Workbook_Open procedure):
Private Sub CheckBirthday()
Dim TodaysDate As Date
Dim FriendName As String
Dim Age As Integer
Dim CheckDates As Object
TodaysDate = Now
'the date the workbook is opened
For Each CheckDates In Range("B2:B5")
If (Mid(CStr(TodaysDate), 1, 5) = Mid(CheckDates, 1, 5)) Then
Age = (Mid(CStr(TodaysDate), 7, 4) - Mid(CheckDates, 7, 4))
FriendName = CheckDates.Offset(0, -1).Value
MsgBox (FriendName & " is " & Age & " years old today")
End If
Next CheckDates
'checks the data held in cells B2 to B5 and compares it with today's date
'if today's date is the same date (not year) of any of the data held in the cells
'then a messagebox will be displayed showing who is celebrating their birthday
End Sub
This assumes that the name of the person is held in column A and the date of birth is in column B. There are headers in A1 and B1. You can amend this to suit your spreadsheet.
Hope this helps.