Enabling and disabling option buttons in Excel using macros

Posted on 2003-11-04
Last Modified: 2010-04-17
I'm working with an excel 2002 file and I have a combo box and some option buttons. Depending on the choice in the combo I have to enable/disable some of the option buttons.
I began programming the macro for the OnChange event of the combo but I need to know which is the piece of code to do that, because the sentence

 Worksheets(name).OptionButton1.Enable = True (Or false)

doesn´t work.

I also think about hide the rows containing the option buttons I have to disable but the problem is that the rows dissapeared but the objects (I mean the option buttons) stay together in a row so that's why I'm trying to disable them.

Any solution or another suggestion will be good!

Thanks in advance.

Question by:lhdarg
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
LVL 69

Expert Comment

ID: 9680320
You have to point to the combo box in order to change properties of buttons within it, so your code should look like: Worksheets(name).ComboBox(myCombo).OptionButton1.Enable = True (Or false)

If your buttons are not on the combo box, your code should work.  I would use the debugger and singlestep through the call to see what it's doing.

Accepted Solution

bhagyesht earned 75 total points
ID: 9684777
use option buttons from the control toolbox instead of option buttons from the form tool box

Author Comment

ID: 9687532
Callandor: I noticed that I was using the wrong object so I inserted the control toolbox option button so now I have the prooperty panel.

Now I'm trying to change the state  (from enable to disable or the other way round) but I don't know how to do it.
The option button is an object separated from the combo box. What I need is to turn to enable (or disable) some option buttons in case the item selected in the combo is something specific.

I tried with

Worksheets(name).OptionButton.Enable = True

but it says the method or property is nos available for that object.

Any solution?



Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Author Comment

ID: 9687736
Sorry, I was using "enable" instead of "enabled".

The sentence

Worksheets(name).OptionButton.Enabled = True


Many thanks.

LVL 69

Expert Comment

ID: 9687976
I tried recording a macro while selecting a button and altering its properties - I could not capture anything I did after selecting the button.  Apparently, not all objects support dynamic change of properties, so it looks like you need to work around the limitation.  You can change the value in a cell in the spreadsheet, depending on what is selected in the combo box, and then when you press the button, test the value in the cell and decide what to do.  Not very elegant, but VBA is limiting what you can do here.

Expert Comment

ID: 9698880
Glad could help!

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this post we will learn different types of Android Layout and some basics of an Android App.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Six Sigma Control Plans

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question