hello,
I want to know how can i execute some vba code on the event of one cell change.
Let's say i have i worksheet, and only when cell A1 change i want some vba to run.
What is the best way to acheive this?
thanks
hello,
I want to know how can i execute some vba code on the event of one cell change.
Let's say i have i worksheet, and only when cell A1 change i want some vba to run.
What is the best way to acheive this?
thanks
Last edited by cesna123; 08-09-2010 at 11:51 AM.
You've pretty much answered your own question - use the change event for the appropriate sheet object.
If you want the code to fire if A1 is the only cell altered then validate the address:
If you want the code to fire if A1 is any one of the cells altered given multiple cells can be updated simultaneously then test the Intersect rather than the address![]()
Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$A$1" Then 'do stuff... End If End Sub
to use either of the above right click on sheet of interest and select View Code pasting above into resulting window.![]()
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target,Range("A1")) Is Nothing Then End If End Sub
Bear in mind if you change the sheet during the course of your routine you will invoke the change event so generally an idea to toggle events appropriately.
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
In the worksheet module of the sheet you want to use
![]()
Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$A$1" Then ' your code here End If End Sub
Hope this helps.
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.
Thanks a lot guys for the solution.
DonkeyOte, thanks for the extra information, also.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks