+ Reply to Thread
Results 1 to 16 of 16

Runing a macro on by changing a value of the cell

  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:

    Please Login or Register  to view this content.
    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.

    Please Login or Register  to view this content.
    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

  7. #7
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679
    Both, actually, but if there is no way of doing that in the same line or two, then a block.

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

    Put this code in place.

    Please Login or Register  to view this content.
    Now if you change A1, you will get the first message. Now highlight the range A1:B5 and press delete, you will get the second message.

    Does that cover your options?

    rylo

  9. #9
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Post

    Please Login or Register  to view this content.
    The alteration to Rylo's code in line 3 above is how you specify the same thing to happen for several different cells, (changed individually), and as Rylo said, the final section (involving the intersect) is for when you change a block of cells including your trigger cell.

    Alternatively if you don't want to differentiate between whether it was affected as a single cell or part of a block then the whole thing will (I think) be a lot simpler, something like:

    Please Login or Register  to view this content.
    Last edited by Phil_V; 09-12-2008 at 03:49 AM. Reason: forgot to remove the 'case' section!

  10. #10
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770
    It's probably worth pointing out that in my last example, because of them being 'Elseif' statements only 1 statement would trigger.

    For example if you had data in the whole range of A1 to F3, then selected the whole lot and pressed delete, you will only get the message for cell A1 changing.
    If you wanted it to trigger for each of the cells that had changed on a block change you would need to change each 'Elseif' to be an 'If' and also insert an 'End If' on the line above each one.

  11. #11
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679
    Exactly what I needed. Thank you very much, guys.

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

    temporarily disabling a macro

    one follow up questions to what we just did. The code above will be used when manually adjusting the cell values. I'll also have another macro that resets these same cells to a certain value by clicking a button.

    How would I temporarily disable the code above while my other macro is running?

    Thanks

  13. #13
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Which code?

    You didn't say who's code worked

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  14. #14
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679
    For now, I'll be using the following:

    Please Login or Register  to view this content.
    I need to disable it while other code runs.

  15. #15
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Try


    Please Login or Register  to view this content.
    VBA Noob

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

+ 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