Doesn't seem to work, unfortunately. It's doing what my attempts did - colors all the cells. Here's the full code including your piece.
Sub TestColor()
Dim r10 As Range
Dim r11 As Range
Sheets("Sheet1").Cells.FormatConditions.Delete
With ActiveWorkbook.Worksheets("Sheet1")
Set r10 = .Range("A:A").Find(What:="Order Date", After:=.Range("A1"), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
End With
Set r11 = Range(r10.Offset(1), r10.End(xlDown).End(xlToRight))
With r11
.FormatConditions.Add Type:=xlTimePeriod, DateOperator:= _
xlLastMonth
' .FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With .FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 49407
.TintAndShade = 0
End With
.FormatConditions(1).StopIfTrue = False
End With
'''''''''''''''test area
Dim cell As Range
Set r12 = Range(r10.Offset(1), r10.End(xlDown))
For Each cell In r12
If cell.FormatConditions(1).Interior.Color = 49407 Then
cell.FormatConditions.Delete
cell.Interior.Color = vbRed
End If
Next cell
'''''''''''''''''end test area
End Sub
To try, in column A enter in cells:
A1 = Order Date
A2 = 9/1/2016
A3 = 10/1/2016
A4 = 11/1/2016
Ideally, when the code runs, it should conditional format just cell A3 (since it's the last month) in 49407 (and it does, if you edit out the test code), then in the test area for those conditionally formatted cells remove the coloring and just fill it with normal red.
But like I said it does all cells
Bookmarks