How do I detect if a certain table column has a certain filter activated?

Klash Ville

Board Regular
Joined
Sep 19, 2017
Messages
83
Hello everyone,

I have a rather complex question... which is the following:

I have a table column header called "Column1" which has the following filter activated through VBA:

Code:
ActiveSheet.ListObjects("Table2").Range.AutoFilter Field:=.ListColumns("Column1").Index, Criteria1:=RGB(255, 199, 206),
Operator:=xlFilterCellColor

This filters for all cells whose color result from the following RGB code combination which was inicially formed through Conditional Formatting. Anyway, I cannot figure out the right way to build an if to detect either if that filter is being activated, or not.

Code:
Basicly, I want this:

If Column1.autofilter = RGB(255, 199, 206) Then
MsgBox "Yes"
Else
MsgBox "No"
End If
 
Last edited:
Hi ,

While I think about it , why not go about it another way ?

As I understand you , you wish to know whether a particular column in a table has been filtered on the colour RGB(255 , 199 , 206) ; is this correct ?

If this is the case , can we not just loop through the visible cells and check for whether even one cell has this interior colour ; if yes , and if a filter is active on the column , it follows that this colour has to be among the criteria.

Is this correct ?
 
Upvote 0

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi ,

While I think about it , why not go about it another way ?

As I understand you , you wish to know whether a particular column in a table has been filtered on the colour RGB(255 , 199 , 206) ; is this correct ?

If this is the case , can we not just loop through the visible cells and check for whether even one cell has this interior colour ; if yes , and if a filter is active on the column , it follows that this colour has to be among the criteria.

Is this correct ?

That is correct, even though loops are not efficient, it's probably the only solution right now.

Could you give me a code suggestion? Also note that this RGB color is originated from Conditional Formating, which has a different behaviour.

But anyways, thank you for all your help so far :)
 
Last edited:
Upvote 0
Hi ,

In that case , even this approach is ruled out , since Conditionally Formatted colors are more difficult to identify.

In case I can think of something , I will post it.
 
Upvote 0
Hi ,

See if this works :

Rich (BB code):
If ActiveSheet.ListObjects("Table2").ListColumns("Column1").DataBodyRange.SpecialCells(xlCellTypeVisible).Cells(1).DisplayFormat.Interior.Color = RGB(255, 199 , 206) Then
 
Upvote 0
Hi ,

See if this works :

Rich (BB code):
If ActiveSheet.ListObjects("Table2").ListColumns("Column1").DataBodyRange.SpecialCells(xlCellTypeVisible).Cells(1).DisplayFormat.Interior.Color = RGB(255, 199 , 206) Then

Hello my friend, sorry for the delay.

I will try this right now and give you feedback right away.
 
Upvote 0
Hi ,

See if this works :

Rich (BB code):
If ActiveSheet.ListObjects("Table2").ListColumns("Column1").DataBodyRange.SpecialCells(xlCellTypeVisible).Cells(1).DisplayFormat.Interior.Color = RGB(255, 199 , 206) Then

Yes! This works flawlessy, thank you so much!

Thank you so much in providing me the solution for this major obstacle I had, it works absolutely well, and it recgonizes my conditional formated cells. It's perfect!

Thank you =)
 
Upvote 0
This is the final working code:

Code:
If ActiveSheet.ListObjects("Table2").ListColumns("Column1").DataBodyRange.SpecialCells(xlCellTypeVisible).Cells(1).DisplayFormat.Interior.Color = RGB(255, 199, 206) Then
            MsgBox "Filter has already been applied"
        Else           
            With ActiveSheet.ListObjects("Table2")
                .Range.AutoFilter field:=.ListColumns("Column1").Index, Criteria1:=RGB(255, 199, 206), Operator:=xlFilterCellColor
            End With
        End If
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,813
Members
449,469
Latest member
Kingwi11y

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