VBA : Filter or Unfilter Data Using Single Button

Susanto3311
3StarLounger
Posts: 240
Joined: 17 Feb 2022, 05:16

VBA : Filter or Unfilter Data Using Single Button

Post by Susanto3311 »

hi all.

i have code to Filter data and working properly, here the code

Code: Select all

Sub unfilter()
Set wkbCrntWorkBook = ActiveWorkbook
Application.ScreenUpdating = False
Application.ScreenUpdating = True
ActiveSheet.AutoFilterMode = False
ActiveWindow.FreezePanes = False
Columns.EntireColumn.Hidden = False
Rows.EntireRow.Hidden = False
End Sub
but i want to modify/add code [in single code/button] can work like this:
1. if the data area have "filtered" , click the button code at first, so data filter is gone
2. and if the data not filtered, click the button again so data filter is showing

i hope someone would help me a solution
.sst

User avatar
HansV
Administrator
Posts: 78531
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: VBA : Filter or Unfilter Data Using Single Button

Post by HansV »

Perhaps

Code: Select all

Sub ToggleFilter()
    Range("A1").AutoFilter
End Sub
Best wishes,
Hans

Susanto3311
3StarLounger
Posts: 240
Joined: 17 Feb 2022, 05:16

Re: VBA : Filter or Unfilter Data Using Single Button

Post by Susanto3311 »

ok HansV, thank you so much. that's great!!