• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Birthday Reminder

chand1230

New Member
I want to make a birthday reminder with a popup message box, the below code works perfect if the birthday is between two dates i.e. if the birthday date is between today and next 14 days, but if there is no birthday in next 15 days than the message box popup does not work.

I want the message popup to display that "There are no Birthday in Next 15 Days" and it should display the popup only once.

Thanks in advance.

Code:
Sub Reminder()

Dim LR As Long, i As Long, msg As String


With Sheets("Sheet1")
  LR = .Range("c" & Rows.Count).End(xlUp).Row
  For i = 1 To LR
  If IsDate(.Range("c" & i)) Then
  'If .Range("A" & i).Value - Date < 30 Then
  
  If .Range("c" & i).Value >= Date And .Range("c" & i).Value <= Date + 14 Then
  
  'msg = msg & .Range("A" & i).Value & vbTab & vbTab & Format(.Range("c" & i).Value, "ddd-dd-mmm-yyyy") & vbCrLf  '& vbCrLf
  msg = msg & .Range("A" & i).Value & " Birthday is on " & Format(.Range("c" & i).Value, "ddd-dd-mmm-yyyy") & vbCrLf  '& vbCrLf
  End If
  End If
  Next i
End With
If msg <> "" Then MsgBox prompt:=Left(msg, Len(msg) - 1), Title:="Upcoming Birthday", Buttons:=vbInformation
End Sub
 

Attachments

  • Birtahday Reminder.xlsb
    16.1 KB · Views: 11
Code:
Sub Reminder()

Dim LR As Long, i As Long, msg As String


With Sheets("Sheet1")
  LR = .Range("c" & Rows.Count).End(xlUp).Row
  For i = 1 To LR
  If IsDate(.Range("c" & i)) Then
  'If .Range("A" & i).Value - Date < 30 Then  
  If .Range("c" & i).Value >= Date And .Range("c" & i).Value <= Date + 14 Then
  
  'msg = msg & .Range("A" & i).Value & vbTab & vbTab & Format(.Range("c" & i).Value, "ddd-dd-mmm-yyyy") & vbCrLf  '& vbCrLf  
msg = msg & .Range("A" & i).Value & " Birthday is on " & Format(.Range("c" & i).Value, "ddd-dd-mmm-yyyy") & vbCrLf  '& vbCrLf 
else
msg ="There are no birthdays in the next 15 days"

 End If

  End If
  Next i
End With
If msg <> "" Then MsgBox prompt:=Left(msg, Len(msg) - 1), Title:="Upcoming Birthday", Buttons:=vbInformation
End Sub
 
Code:
Sub Reminder()

Dim LR As Long, i As Long, msg As String


With Sheets("Sheet1")
  LR = .Range("c" & Rows.Count).End(xlUp).Row
  For i = 1 To LR
  If IsDate(.Range("c" & i)) Then
  'If .Range("A" & i).Value - Date < 30 Then 
  If .Range("c" & i).Value >= Date And .Range("c" & i).Value <= Date + 14 Then
 
  'msg = msg & .Range("A" & i).Value & vbTab & vbTab & Format(.Range("c" & i).Value, "ddd-dd-mmm-yyyy") & vbCrLf  '& vbCrLf 
msg = msg & .Range("A" & i).Value & " Birthday is on " & Format(.Range("c" & i).Value, "ddd-dd-mmm-yyyy") & vbCrLf  '& vbCrLf
else
msg ="There are no birthdays in the next 15 days"

End If

  End If
  Next i
End With
If msg <> "" Then MsgBox prompt:=Left(msg, Len(msg) - 1), Title:="Upcoming Birthday", Buttons:=vbInformation
End Sub

Thank you Very much Hui this is what I wanted thanks a lot
 
Thank you Very much Hui this is what I wanted thanks a lot
Sorry Hui,

It is not working properly it is displaying both messages when there are birthdays in dates

PFA for your reference, I have placed the data in two separate sheets
 

Attachments

  • Birthday Reminder.xlsb
    21.2 KB · Views: 12
Whoops didn't look at all the code

try this:

Code:
Sub Reminder()

Dim LR As Long, i As Long, msg As String

'With Sheets("Sheet1")
With ActiveSheet

  LR = .Range("c" & Rows.Count).End(xlUp).Row
  For i = 1 To LR
  If IsDate(.Range("c" & i)) Then
  'If .Range("A" & i).Value - Date < 30 Then
   
  If .Range("c" & i).Value >= Date And .Range("c" & i).Value <= Date + 14 Then
   
  'msg = msg & .Range("A" & i).Value & vbTab & vbTab & Format(.Range("c" & i).Value, "ddd-dd-mmm-yyyy") & vbCrLf  '& vbCrLf
  msg = msg & .Range("A" & i).Value & " Birthday is on " & Format(.Range("c" & i).Value, "ddd-dd-mmm-yyyy") & vbCrLf  '& vbCrLf
  End If
  End If
  Next i
   
End With
If msg <> "" Then
  MsgBox prompt:=Left(msg, Len(msg) - 1), Title:="Upcoming Birthday", Buttons:=vbInformation
Else
  MsgBox prompt:="There are no Birthdays for the next 15 days", Title:="Upcoming Birthday", Buttons:=vbInformation
End If
End Sub
 
Whoops didn't look at all the code

try this:

Code:
Sub Reminder()

Dim LR As Long, i As Long, msg As String

'With Sheets("Sheet1")
With ActiveSheet

  LR = .Range("c" & Rows.Count).End(xlUp).Row
  For i = 1 To LR
  If IsDate(.Range("c" & i)) Then
  'If .Range("A" & i).Value - Date < 30 Then
  
  If .Range("c" & i).Value >= Date And .Range("c" & i).Value <= Date + 14 Then
  
  'msg = msg & .Range("A" & i).Value & vbTab & vbTab & Format(.Range("c" & i).Value, "ddd-dd-mmm-yyyy") & vbCrLf  '& vbCrLf
  msg = msg & .Range("A" & i).Value & " Birthday is on " & Format(.Range("c" & i).Value, "ddd-dd-mmm-yyyy") & vbCrLf  '& vbCrLf
  End If
  End If
  Next i
  
End With
If msg <> "" Then
  MsgBox prompt:=Left(msg, Len(msg) - 1), Title:="Upcoming Birthday", Buttons:=vbInformation
Else
  MsgBox prompt:="There are no Birthdays for the next 15 days", Title:="Upcoming Birthday", Buttons:=vbInformation
End If
End Sub

Now this is perfect thank's a lot Hui
 
Back
Top