Table of Contents

Option Buttons

If you have more than one option button only one of the option buttons can be selected. To create option buttons in Excel VBA execute the following steps.

1. On the Developer tab click Insert.

2. In the ActiveX Controls group click Option Button.

Create an option button in Excel VBA

3. Drag two option buttons on your worksheet.

4. Right click the first option button (make sure Design Mode is selected).

5. Click View Code.

View Code

Note: you can change the caption and name of a control by right clicking on the control (make sure Design Mode is selected) and then clicking on Properties. Change the captions of the option buttons to Female and Male. For now we will leave OptionButton1 and OptionButton2 as the names of the option buttons.

6. Add the following code line:

If OptionButton1.Value = True Then Range(“D3”).Value = 10

7. Right click the second option button (make sure Design Mode is selected).

8. Click View Code.

9. Add the following code line:

If OptionButton2.Value = True Then Range(“D3”).Value = 20

10. Click the option buttons on the sheet (make sure Design Mode is deselected).

Result:

Option Button 1 True

Option Button 2 True

Although in some situations it can be useful to directly place option buttons on your worksheet option buttons are particularly useful when placed on a Userform.

Leave A Comment

Excel meets AI – Boost your productivity like never before!

At Formulas HQ, we’ve harnessed the brilliance of AI to turbocharge your Spreadsheet mastery. Say goodbye to the days of grappling with complex formulas, VBA code, and scripts. We’re here to make your work smarter, not harder.

Related Articles

The Latest on Formulas HQ Blog