uday
Member
Hi Experts,
I am trying to highlight cells in the A column if the value is date then only it will check for the condition where it will be highlighted if the date is older than the current month and year. I have attached the Macro workbook.
Regards,
Uday
I am trying to highlight cells in the A column if the value is date then only it will check for the condition where it will be highlighted if the date is older than the current month and year. I have attached the Macro workbook.
Regards,
Uday
Code:
Sub highlightDates()
Dim currentMonth As Integer
Dim currentYear As Integer
Dim cellValue As Variant
currentMonth = Month(Date) 'get current month
currentYear = Year(Date) 'get current year
For Each cell In Range("A1:A100") 'loop through cells in column A
cellValue = cell.Value 'get cell value
'if cell value is a date and it's older than the current month
On Error Resume Next
If IsDate(cellValue) And (Month(cellValue) < currentMonth) Or (Year(cellValue) < currentYear) Then
cell.Interior.Color = vbYellow 'highlight cell
End If
Next cell
End Sub