VBA: Highlight header row on Autofilter

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,366
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I found this thread to set a background color to the column header of the column with an autofilter applied.

It works fine on the Worksheet Activate event, but not for the Worksheet Change, Calculate, or Selection Change.

Not sure which on I need, but I'm just looking to apply the background color when the user applies a filter in row 1!

Code:
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Sub filterhighlight()
    Dim flt As Filter
    Dim intCol As Integer
    For Each flt In ActiveSheet.AutoFilter.Filters
        intCol = intCol + 1
        If flt.On Then
            Cells(1, intCol).Interior.ColorIndex = 6
        Else
            Cells(1, intCol).Interior.ColorIndex = xlColorIndexNone
        End If
    Next flt
End Sub
[/FONT]
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Which version of Excel? I would expect Worksheet_Calculate to work for an autofilter.
 
Upvote 0
Do you have any formulae on that sheet?
if not put something like
=SUBTOTAL(2,A1:A100)
into a blank cell.
 
Upvote 0
No, I do not have any formulas on this sheet and usually won't. And yes, adding Subtotal worked, but can it work without the formula?
 
Last edited:
Upvote 0
You could use a selection change event, but that wont change the colour until they select another cell after applying the filter.
 
Upvote 0
You could use a selection change event, but that wont change the colour until they select another cell after applying the filter.

Ok, that makes sense and will work for my needs. I have some conditional formatting applied to highlight the entire row the user has selected, so this will activate the highlight code. Thank you.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top