Sending overdue email alerts based on dates in multiple columns

Cookey5599

New Member
Joined
Mar 22, 2022
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Good afternoon and apologies of this has already been asked but I cant find a thread that details this particular issue.

We have a supplier approval log that shows when a particular certificate expires, as you can see form the attachment it is possible that one supplier could hold multiple certs with multiple expiry dates.

I have amended the following code so that it checks column V and sends an email accordingly, what I cant seem to do is get it to check the other cells (n,r,aa & af)


Private Sub Workbook_Open()
Dim OutApp As Object
Dim OutMail As Object
Dim lLastRow As Long
Dim lRow As Long
Dim sSendTo As String
Dim sSendCC As String
Dim sSendBCC As String
Dim sSubject As String
Dim sTemp As String

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon

' Change the following as needed
sSendTo = "test@company.com"
sSendCC = ""
sSendBCC = ""
sSubject = "Due date reached"

lLastRow = Cells(Rows.Count, 3).End(xlUp).Row
For lRow = 2 To lLastRow
If Cells(lRow, 23) <> "S" Then
If Cells(lRow, 22) <= Date Then
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = sSendTo
If sSendCC > "" Then .CC = sSendCC
If sSendBCC > "" Then .BCC = sSendBCC
.Subject = sSubject

sTemp = "Hi Luke" & vbCrLf & vbCrLf
sTemp = sTemp & "The Quality ceritifcate has expired "
sTemp = sTemp & "for this supplier:" & vbCrLf & vbCrLf
' supplier name is in column F
sTemp = sTemp & " " & Cells(lRow, 6) & vbCrLf & vbCrLf
sTemp = sTemp & "Please take the appropriate "
sTemp = sTemp & "action." & vbCrLf & vbCrLf
sTemp = sTemp & "BR" & vbCrLf

.Body = sTemp
' Change the following to .Send if you want to
' send the message without reviewing first
.Display
End With
Set OutMail = Nothing

Cells(lRow, 23) = "S"
Cells(lRow, 24) = "E-mail sent on: " & Now()
End If
End If
Next lRow
Set OutApp = Nothing
End Sub



If anyone has any suggestions then I would be eternally grateful.

Thanks
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
To check whether any of the target cells has a date earlier than or equal to today's date, try replacing . . .

VBA Code:
If Cells(lRow, 22) <= Date Then

with

VBA Code:
If Cells(lRow, "v") <= Date Or Cells(lRow, "n") <= Date Or Cells(lRow, "r") <= Date Or Cells(lRow, "aa") <= Date Or Cells(lRow, "af") <= Date Then

Hope this helps!
 
Upvote 0
Hi and thanks for coming back to me,

I plugged this in but oddly it just causes the spreadsheet to send emails for all of the suppliers in column V regardless of whether they are overdue are not
 
Upvote 0
Actually, we need to check to make sure that the cell isn't blank before testing whether the date meets the criteria . . .

VBA Code:
If (Len(Cells(lRow, "v")) > 0) And (Cells(lRow, "v").Value <= Date) Or _
    (Len(Cells(lRow, "n")) > 0) And (Cells(lRow, "n").Value <= Date) Or _
    (Len(Cells(lRow, "r")) > 0) And (Cells(lRow, "r").Value <= Date) Or _
    (Len(Cells(lRow, "aa")) > 0) And (Cells(lRow, "aa").Value <= Date) Or _
    (Len(Cells(lRow, "af")) > 0) And (Cells(lRow, "af").Value <= Date) Then

Does this help?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top