Proper VBA check to see if a range is filtered

gravanoc

Active Member
Joined
Oct 20, 2015
Messages
346
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I have a range that occasionally has new columns or rows added to it, and the autofilter on this range then needs to be re-applied to cover the new material. It is not a table. My code for checking the AutoFilter will ignore that the line of code is a condition, and apply or remove it in the If statement. Unlike checking the entire sheet or a list object, there doesn't seem to be a dedicated property that I could find.

VBA Code:
If Not driveRng.AutoFilter Then
    
        driveRng.AutoFilter
    
End If
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
You can compare the filtered range with your range via the Insersect method …​
 
Upvote 0
Autofilter is a method not a property, which is why you get what you describe. There is no relevant property for a range, so you need to test the autofiltermode property of the worksheet to determine if there is a worksheet filter in place, then test if the range is the one you want, as Marc alluded to.
 
Upvote 0

Forum statistics

Threads
1,213,487
Messages
6,113,941
Members
448,534
Latest member
benefuexx

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