+ Reply to Thread
Results 1 to 9 of 9

Running Macro when option button selected

  1. #1
    Registered User
    Join Date
    03-22-2019
    Location
    Portland, Oregon
    MS-Off Ver
    Mac 2016
    Posts
    58

    Running Macro when option button selected

    I have three option buttons to be selected. When one is selected, you can then "activate" your choice by using a dropdown menu. But just selecting an option button will not activate the desired change, so I wish to change the color of the cells behind the button from green to yellow when the button is selected, to indicate that your selection has not been activated. Then, when you do activate with the dropdown menu, that macro changes the cells back to green.

    I've gotten the cells to turn yellow by using a Calculate event in the sheet code for the reference cell connected to the Option Buttons. But my problem is that ANY change event on the sheet will cause the cells behind the selected button to turn yellow. How do I make it so ONLY a change to the reference cell (which is L7) will trigger the color change?

    Here is the code:

    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor Eastw00d's Avatar
    Join Date
    02-29-2020
    Location
    Breda, NL
    MS-Off Ver
    2016, 2019
    Posts
    833

    Re: Running Macro when option button selected

    Maybe I do not understand the problem completely, but what if you try this:
    Please Login or Register  to view this content.
    Cheers
    Erwin
    I started learning VBA because I was lazy ...
    Still developing.... being more lazy...

  3. #3
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Running Macro when option button selected

    Use the WorkSheet_Change event ???

  4. #4
    Registered User
    Join Date
    03-22-2019
    Location
    Portland, Oregon
    MS-Off Ver
    Mac 2016
    Posts
    58

    Re: Running Macro when option button selected

    No, the change event does not work, I believe because I'm not manually changing L7... the Option Button selection is changing it. I've researched online for answers for days now. Most advice is to use "calculate" to trigger a macro if a cell is changed via a formula. This isn't exactly a formula, but in any case, the cell's value is changed by something other than manual entry, so Change Event does not work.

  5. #5
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Running Macro when option button selected

    Why not use one of your other events (option buttons) to trigger colour change, why does it have to be specifically cell value change.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    03-22-2019
    Location
    Portland, Oregon
    MS-Off Ver
    Mac 2016
    Posts
    58

    Re: Running Macro when option button selected

    Hello, torachan, I tried your code but it doesn't work. I changed it to "OptionButton6", because that's what appears in the name box for one of the buttons. But when I click it, the cells do not change color. Your code is sheet code, correct?

    (note, I don't "need" it to be specifically cell value change... I'm just trying to figure out anyway to make it work. Thanks for your help)

  7. #7
    Registered User
    Join Date
    03-22-2019
    Location
    Portland, Oregon
    MS-Off Ver
    Mac 2016
    Posts
    58

    Re: Running Macro when option button selected

    torachan, when I press "play" in VBA your code DOES change the cells color, but it is not being triggered by clicking the button. I noticed on your sheet the button's name is OptionButton1 with no space before the button. On my sheet it is OptionButton 6, with a space before the six. I cannot enter a space into the code without getting an error. I manually changed the button's name to "Jill", and change the code to "Jill_Click", but that didn't work either.

  8. #8
    Registered User
    Join Date
    03-22-2019
    Location
    Portland, Oregon
    MS-Off Ver
    Mac 2016
    Posts
    58

    Re: Running Macro when option button selected

    Finally figured it out. Just needed to write a separate macro, not a sheet event, then assign macro to each option button with right click:

    Please Login or Register  to view this content.

  9. #9
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: Running Macro when option button selected

    Sorry been away from my computer for a few hours.
    Glad you have it sorted now.
    If you need any more help upload your workbook it is a lot easier to work with the total package.

+ 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. Can you refer to a radio option button group to just get the value of the option selected
    By pharmacologist in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-01-2020, 08:54 AM
  2. Replies: 3
    Last Post: 11-18-2019, 09:32 AM
  3. Macro starting running on workbook open, not on option button selection
    By gjwilson1216 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-10-2014, 12:57 PM
  4. Replies: 2
    Last Post: 08-15-2013, 12:25 PM
  5. [SOLVED] Macro to read if option button selected then action..
    By ZeDoctor in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-02-2012, 09:34 AM
  6. Replies: 0
    Last Post: 07-18-2012, 09:45 AM
  7. [SOLVED] Having a macro recognize when an option button has been selected
    By Linking to specific cells in pivot table in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-26-2005, 01:05 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