So I'm trying to make my macro look for each cells on the left of the range columns, that if it isn't empty and is expired/late (See the formula1 days), it will turn red.
Right now, my code isn't optimized but I'm new to VBA coding. I've written it with the logic above.
Sub Macro1()
'
' Macro1 Macro
' This macro is to highlight the cell if it has been more than 5 days
'
' Keyboard Shortcut: Ctrl+b
'
' this is the range of cells
Range("L4:L1000").Select
' this targets any cell value within that range that is above the Formula1 variable which can be adjusted
For Each cell In Range("L4:L1000")
If Not IsEmpty(Range("L4:L1000").Offset(0, -1).Value) Then
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, Formula1:="6"
' this selects which colour you want to highlight the targetted cells to
Selection.FormatConditions(1).Interior.ColorIndex = 3
ActiveWindow.SmallScroll Down:=0
End If
Next
Range("N4:N1000").Select
For Each cell In Range("N4:N1000")
If Not IsEmpty(Range("N4:N1000").Offset(0, -1).Value) Then
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, Formula1:="5"
Selection.FormatConditions(1).Interior.ColorIndex = 3
ActiveWindow.SmallScroll Down:=0
End If
Next
Range("Q4:Q1000").Select
For Each cell In Range("Q4:Q1000")
If Not IsEmpty(Range("Q4:Q1000").Offset(0, -1).Value) Then
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, Formula1:="4"
Selection.FormatConditions(1).Interior.ColorIndex = 3
ActiveWindow.SmallScroll Down:=0
End If
Next
Range("S4:S1000").Select
For Each cell In Range("S4:S1000")
If Not IsEmpty(Range("S4:S1000").Offset(0, -1).Value) Then
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, Formula1:="2"
Selection.FormatConditions(1).Interior.ColorIndex = 3
ActiveWindow.SmallScroll Down:=0
End If
Next
End Sub
Now my problem is that it makes all the blank cells in that column red and if one cell is late, it makes next range cells (in that row) red, while I'd only want the first late one to turn red.