Running Macro on worksheet change

OldManDemosthenes

New Member
Joined
Apr 19, 2011
Messages
38
I feel like this should be an easy one but then here I am....

I am trying to run a macro when something on a worksheet changes

I've tried both of the following codes with no luck:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
[INDENT]If Not Intersect(Target, Worksheets("Inputs").Range("A1:H114")) Is Nothing Then[/INDENT]
[INDENT][INDENT]Call Macro1[/INDENT][/INDENT]
[INDENT]End If[/INDENT]
Application.EnableEvents = True
End Sub

and
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
[INDENT][INDENT]Call Macro1[/INDENT][/INDENT]
Application.EnableEvents = True
End Sub

Thanks
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
1. The code is in the code module of the sheet concerned? (You shouldn't have to qualify with Worksheets("Inputs") if it is.)
2. Type
?Application.enableevents
in the Immediate pane - you're looking for True, if it's false, then type:
Application.EnableEvents=True
and Return to make it true. Then try again.
3. Put a Break, or a Stop command at the beginning of the event handler code so that you go into debug mode when it reaches that line. If it doesn't happen, you're not triggering the event.
 
Upvote 0
I didn't follow you entirely but yes the code was written in the proper worksheet code.

I just re-entered my first code and everything worked. Don't know what happened, but I'm not complaining

Thanks for responding p45cal
 
Upvote 0
It will only work on the sheet that you have the code in. If you want it to work on EVERY worksheet. Put it in the ThisWorkbook part. change the "Worksheet_Change" part into "Worksheet_SheetChange"
 
Upvote 0
I've only been working with the sheet with the code, although I will eventually branch out to other sheets as well. I think I'm probably missing the obvious. I'll tinker with it some more and post back if I can't get it.

Thanks for assisting
 
Upvote 0
what part isn't working? is the event not being recognized, is the macro not doing what it should? MAYBE your macro has a line that enables events? You don't want that.
 
Upvote 0
The macro works fine. I can run it independently without any problems.

What happens is sometimes I will change something on the sheet within the designated range (from the worksheet change code) and the macro will run as planned. Most of the time nothing happens though....

Sorry if I'm coming off a bit frustrated - its been a long day at the end of a very busy week and this model has me a bit fried.
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,448
Members
452,915
Latest member
hannnahheileen

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