Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does ActiveSheet.FilterMode returns False when sheet has filter?

I'm using the following code in an attempt to detect a filter applied to a column in a table and then clear the filter:

If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData

According to Microsoft documentation:

This property is true if the worksheet contains a filtered list in which there are hidden rows.

This doesn't seem to be the case since ActiveSheet.Filtermode only returns True if a cell inside the table where the filter is applied is selected.

  • First question: Is the documentation wrong? Documentation

  • Second question: Is my only option to select a cell inside the table to get the expression to return True?

PS I am using Excel 2010

Edit: Answer to Question 2, Non-select based methods to clear filters...

If ActiveSheet.ListObjects(1).Autofilter.FilterMode Then ActiveSheet.ListObjects(1).Autofilter.Showalldata

like image 541
orson Avatar asked Jun 23 '26 17:06

orson


1 Answers

An easier alternative can be to just AutoFit all rows:

Rows.AutoFit

The issue with that is that it will un-hide and auto fit all rows on the active sheet.


Update from http://www.contextures.com/excelautofilterlist.html

Dim list As ListObject

For Each list ActiveSheet.ListObjects
    If list.AutoFilter.FilterMode Then
        list.AutoFilter.ShowAllData
    End If
Next
like image 85
Slai Avatar answered Jun 27 '26 17:06

Slai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!