I can't set the cell back color for a cell that is hidden via an auto-filter. Does anyone know how to change the cell color without clearing the auto-filter?
Code:
Sub SetCellBackColorForAutoFilteredCell()
Dim r As Range
Dim lo As ListObject
Set r = Range("A1:A3")
r.Value = Application.WorksheetFunction.Transpose(Array("header", 1, 2))
Set lo = ActiveSheet.ListObjects.Add(xlSrcRange, r, , xlYes)
'Hide the cell with value 2 via AutoFilter. Row 3 will be hidden.
lo.Range.AutoFilter Field:=1, Criteria1:="1"
'Set the cell color for rows 2 and 3
With lo.DataBodyRange.Interior
.Color = RGB(255, 0, 0)
End With
'Clear AutoFilter to unhide row 3
lo.Range.AutoFilter Field:=1
'Note that row 3 did not get its cell color changed because it was hidden via the AutoFilter
End Sub