How about something like this, where after ensuring the 3rd column is not nothing (""), we use a Select Case construct to handle the scenarios (modifications in red)? Please test and report back results.
Sub CheckForExpiryDates()
Dim Cell As Range
Dim ExpiryDate As Date
Dim Mail_Msg As String
Dim Mail_Subj As String
Dim Mail_USubj As String
Dim Rng As Range
Dim RngEnd As Range
Dim lngDateSpread As Long
Mail_Subj = "Training"
Mail_USubj = "URGENT: Training"
Set Rng = Worksheets("Sheet1").Range("A2")
Set RngEnd = Rng.Parent.Cells(Rows.Count, Rng.Column).End(xlUp)
Set Rng = IIf(RngEnd.Row < Rng.Row, Rng, Rng.Parent.Range(Rng, RngEnd))
For Each Cell In Rng.Cells
ExpiryDate = Cell.Offset(0, 2)
lngDateSpread = DateDiff("d", Now(), ExpiryDate)
If Cell.Offset(0, 3) = "" Then
Select Case lngDateSpread
Case Is <= 10
Mail_Msg = Cell.Value & "'s Contract is due to expire on " & ExpiryDate & vbCrLf _
& "please advise on extension"
SendEmail Cell.Offset(0, 1), Mail_USubj, Mail_Msg
Cell.Offset(0, 3) = Now()
Case 11 To 20
Mail_Msg = Cell.Value & "'s Contract is due to expire on " & ExpiryDate & vbCrLf _
& "please advise on extension"
SendEmail Cell.Offset(0, 1), Mail_Subj, Mail_Msg
Cell.Offset(0, 3) = Now()
Case Else 'do nothing
End Select
End If
Next Cell
End Sub
Edit: <5 minutes after posting> I just made three changes to the orignal syntax I provided. Please ensure you have copied the last version. If the Select Case is evaluating lngDateSpread, you're good.
Bookmarks