I want to have a macro fire upon a certain event: Range("C3") is changed. How would I program this?
I want to have a macro fire upon a certain event: Range("C3") is changed. How would I program this?
If Target.address=$C3$ then
'''do something
Need to put AB33's code inside ThisWorkbook and apply it to the Worksheet_Change event
How do I apply it to worksheet change event?
First you have to put the code listed below in the right place. Make sure you click on the correct VBA project and then click on the 'This Workbook' option. See the file below.
This Workbook..JPG
bstier![]()
Please Login or Register to view this content.
Put some code in the Worksheet change event like bstier suggested to catch the change, but since you know the exact cell you can use:
Also, bstier I think Intersect will return Nothing if there are no intersecting cells so I think you need to check that it's not Nothing, otherwise it will fail:![]()
Please Login or Register to view this content.
![]()
Please Login or Register to view this content.
Last edited by AKK9; 02-14-2013 at 05:20 PM.
.
- AKK9 -
Sorry, The code worked just fine when I changed C3 but when I changed any other cell I would get an error. So here is the corrected code to ignore the change to other cells.
![]()
Please Login or Register to view this content.
Why not use this in the worksheet module?
When you use the workbook module, you also have to define the sheet it has to apply to.![]()
Please Login or Register to view this content.
For example
![]()
Please Login or Register to view this content.
Last edited by Marcol; 02-14-2013 at 06:32 PM.
If you need any more information, please feel free to ask.
However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....
Also
اس کی مدد کرتا ہے اگر
شکریہ کہنے کے لئے سٹار کلک کریں
If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.
I got in a hurry before and didn't check to see if the code worked properly when I changed a cell other than C3. When I did this after the post I realized that the code was crashing. Since we don't care about the change of the other cells I used an On Error Goto statement to fix this. AKK9 caught this as well as I did but I have had trouble all afternoon with the Excel Forum site not showing all posts and allowing me to make timely corrections. Thanks for the double check AKK9
Anyway, this code should be in the Sheet1(Sheet1) and not the ThisWorkbook. Thanks Marcol
![]()
Please Login or Register to view this content.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks