Forum Discussion

LauraMuniak's avatar
LauraMuniak
Copper Contributor
May 05, 2024

Macro Notification

Hello, 

 

I need to create macro with pop up notification. I want notification to pop up 3 times

28 days till due date

14 days till due date 

7 days till due date 

4 Replies

  • NikolinoDE's avatar
    NikolinoDE
    Gold Contributor

    LauraMuniak 

    Here is an example code with an example file of how it could work.

    The macro is automatically activated when the workbook is opened.

    This macro will check the value in cell A1 for a due date. If there is a valid date, it calculates the number of days left until that due date. Then it displays notifications at 28, 14, and 7 days before the due date. If the due date is in the past or if there is no valid date in cell A1, no notifications will be displayed.

    Sub DueDateNotification()
        Dim DueDate As Date
        
        ' Check if there's a date in cell A1
        If IsDate(Range("A1").Value) Then
            DueDate = Range("A1").Value
            
            ' Calculate the number of days until the due date
            Dim DaysLeft As Integer
            DaysLeft = DateDiff("d", Date, DueDate)
            
            ' Check if the due date is in the future
            If DaysLeft > 0 Then
                ' Notify 28 days before due date
                If DaysLeft <= 28 And DaysLeft > 14 Then
                    MsgBox "You have 28 days until the due date.", vbInformation
                End If
                
                ' Notify 14 days before due date
                If DaysLeft <= 14 And DaysLeft > 7 Then
                    MsgBox "You have 14 days until the due date.", vbInformation
                End If
                
                ' Notify 7 days before due date
                If DaysLeft <= 7 Then
                    MsgBox "You have 7 days until the due date.", vbInformation
                End If
            End If
        End If
    End Sub

    My answers are voluntary and without guarantee!

     

    Hope this will help you.

     

    Was the answer useful? Mark as best response and Like it!

    This will help all forum participants.

     

    • LauraMuniak's avatar
      LauraMuniak
      Copper Contributor

      NikolinoDE is it possible to do few of them in one spreadsheet and all of them to open on opening of work book 

      • NikolinoDE's avatar
        NikolinoDE
        Gold Contributor

        LauraMuniak 

        Here is another example with the file. It looks in all worksheets and if the date fits into the schema of the requirement in any worksheet in A1.

        The file opens in this worksheet and a window appears where it informs you in which sheet the date is close or how many days are left.

         

        Anyway, take a look at the file.

         

        Hope it helps.

Resources