+ Reply to Thread
Results 1 to 7 of 7

Macro run depending on cell value

  1. #1
    Forum Contributor
    Join Date
    04-21-2009
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    710

    Macro run depending on cell value

    Hi everyone, I had a problem

    I would like to run a macro based on a cell value.

    The cell that contains the value is cell M3.

    If m3 is less than 5 I want it to do nothing.

    If it is between 5 and 10, I want it to run macro 3

    if it is over 10 i want it to run macro 4.

    Simple??

  2. #2
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Macro run depending on cell value

    Yes, this should be straightforward. I take it you want the relevant procedure to be called when M3 is changed? If yes, then does M3 contain a formula (it would change when the worksheet is calculated) or a constant (it would change when someone types in a new value)?
    Hope that helps,

    Colin

    RAD Excel Blog

  3. #3
    Forum Contributor
    Join Date
    04-21-2009
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    710

    Re: Macro run depending on cell value

    Hi Colin, yes when M3 is changed and M3 is calculated from a formula

  4. #4
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Macro run depending on cell value

    Hi,

    Right click on the sheet's tab > View code.

    Copy and paste in this procedure:
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    04-21-2009
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    710

    Re: Macro run depending on cell value

    Hi Colin thanks for that. Something isn't quite right though as the macro it calls for seems to freeze, or get stuck (it continually loops the first part by the looks of things). Is there a conflict somewhere?

    My macro 3 code is as follows

    Please Login or Register  to view this content.
    Last edited by cmb80; 02-17-2011 at 07:58 AM.

  6. #6
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Macro run depending on cell value

    The actions you are performing in that macro are causing the calculate event to be raised: your code is calling itself recursively. To get around this you have to temporarily set Application.EnableEvents to False - but you must ensure it gets set back to True before the procedure ends.

    I've tidied up the code and incorporated this for you:

    Please Login or Register  to view this content.
    You may well find that you have to perform a similar exercise with Macro4.

  7. #7
    Forum Contributor
    Join Date
    04-21-2009
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    710

    Re: Macro run depending on cell value

    Fantastic - and so quick. Thanks for your assistance

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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