highlight filtered cell

Jagat Pavasia

Active Member
Joined
Mar 9, 2015
Messages
359
Office Version
  1. 2021
Platform
  1. Windows
I have Filter from A1 to R1,

I want that if i filter any cell (A1 to R1) than highlight it with change the colour .
so that i can easily find that which cell are filtered.

give me developer code etc. please help
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Place in SHEET module [right-click sheet tab\ select View Code \ paste VBA into code window \ return to Excel with {ALT}{F11} ]
Code:
Sub ColourFilteredHeaders()
    Dim i As Long
    On Error Resume Next
    Range("A1:R1").Interior.ColorIndex = xlNone
    With Me.AutoFilter
        For i = 1 To .Filters.Count
            If .Filters(i).On Then Me.Cells(1, i).Interior.ColorIndex = 50
        Next i
    End With
End Sub
 
Last edited:
Upvote 0
Do you want the macro to run whenever filter is changed?
- here is one way...

Your data finishes in column R
Leave one column empty
Formula goes formula in row 1 in next column (ie T1)

Place this formula in cell T1
=SUBTOTAL(3,A:A)

Paste VBA into SHEET module
Code:
Private Sub Worksheet_Calculate()
    Call ColourFilteredHeaders
End Sub

Why it works?
- the subtotal formula is counting FILTERED rows which change when filter changes
- formula is recalculated which triggers Worksheet_Calculate event
- Worksheet_Calculate runs ColourFilteredHeaders
 
Upvote 0
error occur with yellow highlight on view code page,

Compile error:
Sub or Function not defined
 
Upvote 0

Forum statistics

Threads
1,215,374
Messages
6,124,569
Members
449,173
Latest member
Kon123

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