+ Reply to Thread
Results 1 to 9 of 9

Execute macro based on cell value

  1. #1
    Registered User
    Join Date
    01-26-2011
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    49

    Execute macro based on cell value

    Hi,

    I have a combo box on Sheet5 where the user chooses one of two options. The combo box spits out "1" or "2" in cell AA7. Then I have two macros: "SPOR" and "Avg_Chk", which change a bunch of calculations on the sheet. I would like the "SPOR" macro to be executed if the value in AA7 is "1" and the "Avg_Chk" macro when the value in AA7 is "2".

    I googled and found lots of answers and solutions for this, but when I try to apply them to my worksheet nothing happens when I change the combo box. This is the code I found:

    Please Login or Register  to view this content.
    I add this to the code of Sheet 5. Macro "Spor" and "Avg_Chk" are saved in a module.

    My apologies, I know little to nothing of VBA. I'm sure this is a very obvious mistake and I'm sorry for my noobishness :D

    Thank you for your help!

    Cheers

    M.
    Last edited by Maike; 07-25-2017 at 08:39 AM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Execute macro based on cell value

    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Re: Execute macro based on cell value

    I think you need to actually Call the Macro

    Please Login or Register  to view this content.
    Also, you could think about possibly running/calling the macro within the userform and using ComboBox1_Change() Then when you change the ComboBox between 1 and 2 you can call your macro right there.

    Untested
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-26-2011
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Execute macro based on cell value

    Quote Originally Posted by ptmuldoon View Post
    I think you need to actually Call the Macro
    It looks like the problem is with the combo box and not with the macro itself. Selecting the different choices in the combo box accurately updates the value in AA7 to "1" or "2". Problem is the macro does not recognize that as change. If I type "1" or "2" in AA7 on the other hand, it triggers right away.

    Thank you for your other suggestion. Unfortunately I have 0 experience with Userforms. I had a look at my VBA and there is a userform1. I copied your formulas from above but it didn't do what I was hoping it would. What am I doing wrong? ^.^

    Thanks!

    M.
    Last edited by Maike; 07-24-2017 at 03:57 PM.

  5. #5
    Valued Forum Contributor
    Join Date
    04-24-2014
    Location
    United States
    MS-Off Ver
    Office 365 ProPlus
    Posts
    853

    Re: Execute macro based on cell value

    Attached is a basic userform to help you get started.

    When you open the form, Selecting 1 will call the SPOR macro, and pressing 2 will call the Average Check.

    You can swap out the message boxes for your actual code, and you can also have the userform add the value to Cell AA7 if you would like.
    Attached Files Attached Files

  6. #6
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Execute macro based on cell value

    My bad, I thought you were referring to a dropdown using data validation, since you were using the Worksheet_change event. You may have to consider worksheet_calculate.

    Not sure what type of combo-box you are using though.

  7. #7
    Registered User
    Join Date
    01-26-2011
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Execute macro based on cell value

    Hey ptmuldoon,

    Thank you, that works nicely. I had hoped for one less window though. With your solution the user clicks a button, get's a combo box window that pops open and they choose 1 or 2. I would prefer to have the combo box right on the worksheet. any chance you can help me with that? I really appreciate your time, thank you!

    Cheers

    M.

  8. #8
    Registered User
    Join Date
    01-26-2011
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Execute macro based on cell value

    Quote Originally Posted by davesexcel View Post
    My bad, I thought you were referring to a dropdown using data validation, since you were using the Worksheet_change event. You may have to consider worksheet_calculate.

    Not sure what type of combo-box you are using though.
    Hey Davesexcel,
    I use the combobox form control, the non active-x one. Unfortunately I don't understand enough of VBA to be able to turn "consider worksheet_calculate" into a macro. Thank you for your time though.

  9. #9
    Registered User
    Join Date
    01-26-2011
    Location
    Canada
    MS-Off Ver
    Office 365
    Posts
    49

    Re: Execute macro based on cell value

    Actually, never mind! I was able to use an active X combo box together with the combo box change code you gave me ptmuldoon.

    Works exactly as I had hoped.

    Thanks so much!

+ 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 execute based on a cell value change - if enter is not pressed
    By DJDRU in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-01-2016, 11:52 PM
  2. Execute different equations based on the value of a single cell
    By s86design in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-24-2016, 01:33 PM
  3. Execute a macro in a closed workbook, or open and execute without the user noticing
    By cearaujo123 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-09-2015, 06:44 PM
  4. Execute code based on cell entry
    By rkjudy in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 10-29-2009, 01:38 PM
  5. [SOLVED] How do I execute a macro based on the value of a cell in Excel?
    By brettopp in forum Excel General
    Replies: 12
    Last Post: 06-16-2006, 08:30 PM
  6. [SOLVED] How can I get a macro to execute in excel based on the value of a.
    By Ian P in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-19-2005, 05:06 PM
  7. Execute Events Based Upon Selected Cell
    By D.Parker in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-22-2005, 11:07 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