Hi,
I have a spreadsheet with 45 columns. It is used to refine a data set. It is necessary to filter and sort in each step. For any one of several reasons I often apply a filter, then forget it is there. I am trying to write code that will change the color of the header row when any column is filtered, and change it back when the filter is removed from the column. The filter is always on, but not always applied.
I have this so far, but have a problem with selecting the range; it selects all rows captured in the filter and I just want the filter. I also would like it to be activated by applying a filter. In other words, when I apply a filter, the entire header/row 1 range becomes colored, and when I remove it, the color is removed.
I have a spreadsheet with 45 columns. It is used to refine a data set. It is necessary to filter and sort in each step. For any one of several reasons I often apply a filter, then forget it is there. I am trying to write code that will change the color of the header row when any column is filtered, and change it back when the filter is removed from the column. The filter is always on, but not always applied.
I have this so far, but have a problem with selecting the range; it selects all rows captured in the filter and I just want the filter. I also would like it to be activated by applying a filter. In other words, when I apply a filter, the entire header/row 1 range becomes colored, and when I remove it, the color is removed.
Code:
Sub FilterCheck()
Dim Sht As Worksheet
Dim i As Long
Set Sht = ActiveSheet
With Sht.AutoFilter
For i = 1 To .Filters.Count
If .Filters(i).On Then
Range("$A$1:$AS$85").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
Next i
End With
End Sub