ListObject AutoFilter FilterMode

wsnyder

Board Regular
Joined
Sep 23, 2018
Messages
223
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Using Excel 365.

My snippet is throwing an error here
VBA Code:
If lo.FilterMode Then

Not sure why that is?

Thanks
-w

Full snippet:
Code:
Sub ShowAll_Lists()

Dim wb As Workbook
Dim ws As Worksheet
Dim lo As ListObject

Set wb = ThisWorkbook

For Each ws In wb.Worksheets
    For Each lo In ws.ListObjects
        With lo.AutoFilter
            If lo.FilterMode Then
                lo.ShowAllData
            Else
                lo.ShowAutoFilter = True
            End If
        End With
    Next lo
Next ws
Set wb = Nothing

End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Looks like I solved it
This will show all if the Table is filtered and add filter buttons if the Table is not filtered

thanks,
-w


VBA Code:
Sub ShowAll_Lists()

Dim wb As Workbook
Dim ws As Worksheet
Dim lo As ListObject

Set wb = ThisWorkbook

For Each ws In wb.Worksheets
    For Each lo In ws.ListObjects
        If Not lo.AutoFilter Is Nothing Then
            lo.AutoFilter.ShowAllData
        Else
            lo.ShowAutoFilter = True
        End If
    Next lo
Next ws
Set wb = Nothing

End Sub
 
Upvote 0
Solution
Here another option to consider:

VBA Code:
Sub ShowAll_Lists()
  Dim wb As Workbook
  Dim ws As Worksheet
  Dim lo As ListObject
  
  Set wb = ThisWorkbook

  For Each ws In wb.Worksheets
    For Each lo In ws.ListObjects
      If lo.ShowAutoFilter Then
        lo.AutoFilter.ShowAllData
      Else
        lo.Range.AutoFilter
      End If
    Next lo
  Next ws
End Sub
 
Upvote 0
Here another option to consider:

VBA Code:
Sub ShowAll_Lists()
  Dim wb As Workbook
  Dim ws As Worksheet
  Dim lo As ListObject
 
  Set wb = ThisWorkbook

  For Each ws In wb.Worksheets
    For Each lo In ws.ListObjects
      If lo.ShowAutoFilter Then
        lo.AutoFilter.ShowAllData
      Else
        lo.Range.AutoFilter
      End If
    Next lo
  Next ws
End Sub
You can also do it with just
VBA Code:
If lo.AutoFilterMode Then
, which is what I posted above. It'll tell you if it's on.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

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