Autofilter VBA without button

happyhungarian

Active Member
Joined
Jul 19, 2011
Messages
252
Office Version
  1. 365
Platform
  1. Windows
Hi,

Is it possible for an autofilter macro be setup in a way that when I update a cell that contains my criteria, the autofilter automatically runs without having to click a button to which it has been assigned? Basically, I have a section containing 7 cells that each have a seperate criteria. If the user of my workbook wants to narrow down their filter results, they will have to click the refresh button each time they change the criteria. I want the results to automatically start updating as the user adds more criteria.

Thank you,

Jesse
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi

You can probably use one of the Worksheet events. Right click on the worksheet tab and choose View Code. This will open the VB Editor. There are two dropdowns (one should say General and the other Declarations). Choose Worksheet from the first one and then Change from the second. This should create an empty procedure for you that looks like this:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

End Sub

You can now write code that runs any time someone changes a cell in that worksheet. The Target argument tells you which cell(s) were changed so you can use this to determine if the changed cells were one of the 7 criteria cells that you set up. An easy way to do this is to name the criteria cells (say "Criteria") and then use something like this:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Me.Range("Criteria"), Target) Is Nothing Then Exit Sub

'Run your autofilter code here

End Sub

HTH
DK
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,219
Members
452,895
Latest member
BILLING GUY

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