VBA Code to Automatically Re-apply Filter

JNimports

New Member
Joined
Nov 6, 2019
Messages
10
Hi - does anyone have a working VBA code to automatically reapply a number filter on greater than 0? I have tried 3 or 4 codes that I found by searching but none of them actually seem to do anything! It is possible that I'm doing something wrong in the applying of them though.. :confused:
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Most things are possible, and in answer to your question about applying code... you probably are doing something wrong!

What is the first number filter? What have you tried?
 
Upvote 0
Can you explain exactly what you mean by "automatically reapply", please explain your process?

Can you also let us know the range of your data and the range that you are applying the filter to (and the sheet name if there is any chance that you could be on any other sheet when running the code) as it is a bit difficult writing any code without them ;)
 
Upvote 0
That is a very distinct possibility!

The filter is greater than 0. When a value is entered in one of the first 3 tabs, I want the filter on the fourth tab to update and show the corresponding row, it is pulling the value through with a VLOOKUP.
 
Upvote 0
Try

Code:
If Worksheets("Totals").FilterMode = True Then Worksheets("Totals").FilterMode = False
Worksheets("Totals").Range("E5:E367").AutoFilter 1, ">0", xlAnd

Please note that it won't run automatically in a Worksheet_Change or a Worksheet_SelectionChange event as these don't fire with a change of formula result.
 
Upvote 0
The autofilter object has an ApplyFilter method which will reapply whatever filters are currently set.
 
Upvote 0
Try

Code:
If Worksheets("Totals").FilterMode = True Then Worksheets("Totals").FilterMode = False
Worksheets("Totals").Range("E5:E367").AutoFilter 1, ">0", xlAnd

Please note that it won't run automatically in a Worksheet_Change or a Worksheet_SelectionChange event as these don't fire with a change of formula result.

I must be doing something wrong as it is not working, when I enter a value in another tab the fourth tab stays filtered..
 
Upvote 0
Is your data in a table, or just a normal range?
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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