+ Reply to Thread
Results 1 to 16 of 16

Runing a macro on by changing a value of the cell

Hybrid View

  1. #1
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    Runing a macro on by changing a value of the cell

    Is there a way to change the value of cell A1, for example, from one value to another, hit the enter key, and activate a macro this way.

    A couple of qualifications:
    - the value in cell A1 will never be the same (that is it could be -23.43 or .12)
    - I can not simply tie the macro to the "enter" key as there will be numerous cells (A1, B3, C90 and so on) in the same sheet that I will need to do this with, each tied to a different macro.

    Thanks for your help.

  2. #2
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770
    Right click on the worksheet's tab, View Code.

    Paste the following code:

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Select Case Target
        Case Range("A1")
            MsgBox "You changed A1"
        Case Range("F3")
            MsgBox "You changed F3, and yes this is a different message"
    End Select
    End Sub
    Change cell A1 and you'll get the message, change cell F3 and you'll get the other message. Any other cell does nothing. This code certainly isn't polished or bullet-proof, but it should give you the idea to start with

  3. #3
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679
    that gets me closer! The only trouble is when I delete the value in any other cell, say B6, the first message appears....

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Try this.

    Private Sub Worksheet_Change(ByVal Target As Range)
    Select Case Target.Address
        Case "$A$1"
            MsgBox "You changed A1"
        Case "$F$3"
            MsgBox "You changed F3, and yes this is a different message"
    End Select
    End Sub
    Note that if you highlight say A1:B3 and delete, you won't get any message. It is currently set to only action on single cells.
    rylo
    Last edited by rylo; 09-11-2008 at 09:00 PM. Reason: Added note comment

  5. #5
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679
    great, that works!

    If I wanted to call the same macro with changes in cells A1 and B1 and C4, what code would I need to insert in the 3rd line?

    Thanks

  6. #6
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Sorry, don't follow. Do you want it to action if you have a block of cells selected, or do you wish to nominate additional single address locations?


    rylo

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro to insert formatted row above active cell?
    By jojojojo5 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-25-2012, 03:53 PM
  2. Macro to tell cell to become cell + 1
    By masterott in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-27-2007, 02:43 PM
  3. Matching a cell ref. in a macro
    By tuph in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-17-2007, 10:30 PM
  4. How to make a macro work in a row but not on a certain cell
    By Cellar Webs in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-16-2007, 01:17 PM
  5. Change populated cell names via macro
    By TJM in forum Excel General
    Replies: 2
    Last Post: 09-12-2006, 10:47 PM

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