Activate macro when data is entered into a cell

RogerC

Well-known Member
Joined
Mar 25, 2002
Messages
533
I have a filter macro that I would like to run if a user enters any data into a certain range of cells. Does anyone know if it is possbile to have a macro execute when data (any data) has been entered into a range of cells? Thanks!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

dk

MrExcel MVP
Joined
Feb 15, 2002
Messages
2,942
Yes, this is possible.

Say you want to run your macro if data is entered into range A1:D10

Right click the worksheet tab and click View Code. This will open the code module of that worksheet. Use code like this:-

<pre>
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Me.Range("A1:D10")) Is Nothing Then YourMacroName
End Sub
</pre>

The worksheet change event is one of Excel VBA's built in events. You can write code like that above to repond to user actions.
 

RogerC

Well-known Member
Joined
Mar 25, 2002
Messages
533
Dan- thanks so much for your help. I tried using your code... substituting my data range and the name of my macro for YourMacroName, of course. When I enter data into my range I get a 'Compile Error - Ambiguous Name Detected: Worksheet_Change'. Can you tell me what to look for now? BTW, I'm using one other WorkSheet_Change Private Sub in the same worksheet and it works fine. Thanks!
 

PaddyD

MrExcel MVP
Joined
May 1, 2002
Messages
14,234
you can only have 1 worksheet_change event per worksheet. Stick the new code in the other one...

Paddy
 

RogerC

Well-known Member
Joined
Mar 25, 2002
Messages
533
Thank you Paddy and Dan... it's working perfectly! Now I know! :)
 

Forum statistics

Threads
1,144,765
Messages
5,726,175
Members
422,660
Latest member
mrsteele

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
Top