How to alert due date in excel through mail
To alert due dates in Excel through email, you can use a combination of formulas, conditional formatting, and VBA macros. Here's a step-by-step guide to help you achieve this:
Step 1: Prepare your data
- Create a table in Excel with the following columns:
- Due Date (in a format that Excel can recognize, such as MM/DD/YYYY)
- Task/Project Name
- Email Address (the email address you want to send the alert to)
- Make sure the due dates are in a column that can be easily referenced by formulas.
Step 2: Create a formula to check due dates
- In a new column, create a formula that checks if the due date is today's date or earlier. You can use the following formula:
=IF(TODAY()>=A2, "OVERDUE", "ON TIME")
Assuming the due date is in column A, this formula checks if today's date is greater than or equal to the due date. If it is, the formula returns "OVERDUE", otherwise it returns "ON TIME".
Step 3: Create a conditional formatting rule
- Select the cells in the new column that contain the formula (from Step 2).
- Go to the Home tab > Conditional Formatting > New Rule.
- Select "Use a formula to determine which cells to format".
- Enter the following formula:
=A2="OVERDUE"
This formula checks if the value in the new column is "OVERDUE". If it is, the cell will be formatted with a specific color or style.
Step 4: Create a VBA macro to send emails
-
Open the Visual Basic Editor by pressing Alt+F11 or by navigating to Developer > Visual Basic.
-
In the Editor, create a new module by clicking Insert > Module.
-
Paste the following code:
Sub SendEmailDueDateAlert() Dim ws As Worksheet Set ws = ThisWorkbook.Worksheets("YourSheetName") Dim lastRow As Long lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row Dim i As Long For i = 2 To lastRow If ws.Cells(i, "B").Value = "OVERDUE" Then Dim email As String email = ws.Cells(i, "C").Value Dim subject As String subject = "Due Date Alert: " & ws.Cells(i, "A").Value Dim body As String body = "This is a reminder that the due date for " & ws.Cells(i, "B").Value & " is " & ws.Cells(i, "A").Value & "." Dim olApp As Object Set olApp = CreateObject("Outlook.Application") Dim olMail As Object Set olMail = olApp.CreateItem(0) With olMail .To = email .Subject = subject .Body = body .Send End With Set olMail = Nothing Set olApp = Nothing End If Next i End Sub
Replace "YourSheetName" with the actual name of your worksheet.
Step 5: Set up the macro to run automatically
- Go back to the Visual Basic Editor and click Tools > References.
- Check the box next to "Microsoft Outlook Object Library" to enable Outlook integration.
- Close the Editor and return to your Excel worksheet.
- Go to the Developer tab > Macros > Run.
- Select the "SendEmailDueDateAlert" macro and click Run.
Step 6: Schedule the macro to run automatically
- Go to the File tab > Options > Add-ins.
- Check the box next to "Excel Add-ins" and click Go.
- In the Add-ins dialog box, select the "SendEmailDueDateAlert" macro and click OK.
- Close the dialog box and return to your Excel worksheet.
Now, every time the due date is reached, the macro will send an email to the specified email address with the task/project name and due date.