+ Reply to Thread
Results 1 to 4 of 4

specific cell change event

Hybrid View

  1. #1
    Registered User
    Join Date
    06-22-2010
    Location
    ontario
    MS-Off Ver
    Excel 2007
    Posts
    16

    specific cell change event

    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.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: specific cell change event

    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:

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Address = "$A$1" Then
            'do stuff...
    
        End If
    End Sub
    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 Not Intersect(Target,Range("A1")) Is Nothing Then
    
    
        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.

    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.

  3. #3
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: specific cell change event

    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.

  4. #4
    Registered User
    Join Date
    06-22-2010
    Location
    ontario
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: specific cell change event

    Thanks a lot guys for the solution.
    DonkeyOte, thanks for the extra information, also.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1