I want to create a Msgbox alert to tell me when employees' contract are coming to an end.
Those contract which are between 4 - 1 month(s) of expiry will have their cells filled in Red:
This is my code thus far:
Private Sub workbook_open()
Dim rngData As Range
Dim rngCell As Range
Dim counter As Long: counter = 0
Set rngData = Range("E4:E" & Cells(Rows.Count, Range("E3").Column).End(xlUp).Row)
For Each rngCell In rngData
If rngCell.Value = "4" Or rngCell.Value = "3" Or rngCell.Value = "2" Or rngCell.Value = "1" And rngCell.Value <> "" Then
counter = counter + 1
End If
Next rngCell
MsgBox counter & " employees are reaching their contract expiration date!"
Range("A4:E13").Sort _
Key1:=Range("E4"), Order1:=xlAscending
End Sub
However, how do I include a line of code to tell me the EE No. of the employees whose contract are expiring, to be shown in the Msgbox as well?

If rngCell.Value = "4" Or rngCell.Value = "3"...Is there a formula in theMonths Leftcolumn? - Siddharth Rout