Run a Macro everytime a change is made to a worksheet

brumby

Active Member
Joined
Apr 1, 2003
Messages
400
Hiya folks.

Is it possible to run a filter macro everytime a change is made to a specific worksheet?

I have a sheet called "Master Production Plan", which feeds a summary sheet called "PROD PLAN", I have a macro as below, which I would like to autorun each time I make a change to Master Production Plan

ActiveSheet.Range("$A$4:$AT$144").AutoFilter Field:=2, Criteria1:=Array("1" _
, "2", "3", "4", "5", "6", "7", "8", "9", "10"), Operator:=xlFilterValues

Can anyone help?

Many Thanks!!!!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hiya folks.

Is it possible to run a filter macro everytime a change is made to a specific worksheet?

I have a sheet called "Master Production Plan", which feeds a summary sheet called "PROD PLAN", I have a macro as below, which I would like to autorun each time I make a change to Master Production Plan

ActiveSheet.Range("$A$4:$AT$144").AutoFilter Field:=2, Criteria1:=Array("1" _
, "2", "3", "4", "5", "6", "7", "8", "9", "10"), Operator:=xlFilterValues

Can anyone help?

Many Thanks!!!!

Hi,

Which sheet should the autofilter be applied to?

Dom

Judging by the existing code it is the active sheet, the same one with data being entered into it to run the macro.

Brumby, try adding the following code directly to the Master Production Plan sheet by right-clicking the sheet tab and selecting View Code. Obviously you will need to change YOURFILTERMACRO to whatever you have called your existing code. You can also tweak the range A1:Z100 to suit your data.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A1:Z100")) Is Nothing Then Exit Sub Else
Call YOURFILTERMACRO
End Sub
 
Upvote 0
Hi There........thanks for the advice, its as below

I enter the data into "Master Production Plan"

The Macro to filter is in "PROD PLAN" worksheet,

sorry for the confusion

appreciate your help guys!!!
 
Upvote 0
Hi There........thanks for the advice, its as below

I enter the data into "Master Production Plan"

The Macro to filter is in "PROD PLAN" worksheet,

sorry for the confusion

appreciate your help guys!!!
If the filter isn't going to be happening on the Master Production Plan sheet then you will need to recode your filter macro because of this bit:

Rich (BB code):
ActiveSheet.Range("$A$4:$AT$144").AutoFilter Field:=2, Criteria1:=Array("1" _
, "2", "3", "4", "5", "6", "7", "8", "9", "10"), Operator:=xlFilterValues

If you change this line in your filter macro to this...:

Rich (BB code):
Worksheets("PROD PLAN").Range("$A$4:$AT$144").AutoFilter Field:=2, Criteria1:=Array("1" _
, "2", "3", "4", "5", "6", "7", "8", "9", "10"), Operator:=xlFilterValues

...then Excel will not try to apply the filter to Master Production Plan, which would be the ActiveSheet.
 
Upvote 0
SUPERB!!!! thanks guys, works a treat
Happy to help, glad we got there in the end. Feel free to click the like button on the posts with answers to help anyone else with a similar query find the solutions faster.
 
Upvote 0

Forum statistics

Threads
1,214,853
Messages
6,121,935
Members
449,056
Latest member
denissimo

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