VBA to reset filter to greater than zero after worksheet change

capnbigal

New Member
Joined
Aug 23, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I have a dashboard with data slicers on a worksheet called "Charts" and then on another worksheet called "DT_Summary" that has 7 pivot tables running vertically in columns D150:E400.
I also have a table in DT_Summary ranging from A1:B100 that has a static list of all of my Downtime reasons, and a sumif in column B to sum up all pivot values between E150:E400.

I am trying to make the VBA refilter B1 of my table on DT_Summary to all values greater than zero, so that my chart on sheet "Charts" only displays downtime reason with > 0 downtime when the date slicers are adjusted.
I've tried recording a macro and applying other solutions but can not figure this out. I've tried putting the Worksheet_Change code below on the Charts sheet and reference the DT_Summary table and also just have tried it on the DT_Summary table. Can anyone tell me what I am doing wrong or how to fix? Thank you

```
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
    Sheets("DT_Summary").Select
    ActiveSheet.ListObjects("Table3").Range.AutoFilter Field:=2, Criteria1:= _
        ">0", Operator:=xlAnd
Application.EnableEvents = True
End Sub
```
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I was able to get it working with this code:

VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Application.ScreenUpdating = False

Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("DT_Summary")

With ws
  If Not .AutoFilterMode Then .Range("A1").AutoFilter

     'First Critiera
     .Range("A1").AutoFilter Field:=2, Criteria1:=">0"
     .AutoFilterMode = False
End With

Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,528
Messages
6,120,065
Members
448,941
Latest member
AlphaRino

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