WiseOwl Training - Established 1992 Wise Owl Training

Established May 1992
30 years in business
Wise Owl Training
30 years in business
See 519 reviews for our classroom and online training
Advanced controls in userforms with VBA macros
Part eight of a nine-part series of blogs

The two previous parts of this mini-blog have shown how to draw forms and how to write code to handle form events. This final part shows how to add some of the more exotic controls to user forms, like combo boxes, list boxes, multipage controls, spinners and option buttons.

  1. Advanced Controls - Our Example
  2. Multipage Controls
  3. Combo boxes (and list boxes)
  4. Multiple Column Combo Boxes and Listboxes
  5. Multi-select ListBoxes
  6. SpinButtons (Spinners)
  7. Check Boxes
  8. Option Buttons (Radio Buttons) (this blog)
  9. The Calendar Control

This blog is part of our Excel VBA tutorial.  Wise Owl's main business is running Excel, VBA and other courses for businesses.

Posted by Andy Brown on 28 February 2012

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Option Buttons (Radio Buttons)

An option button (sometimes called a radio button) allows you to choose between mutually exclusive possibilities:

Option buttons for milk choice

You can have no milk, skimmed or normal milk, but you must choose one and one only possibility.


I'd avoid option buttons like the plague: a combo box is easier to create, and makes it much easier to add additional options that you've forgotten (semi-skimmed milk, anyone?).  I've only included this page because some clients or managers will ask for option buttons!

How Option Buttons Work

In a group of option buttons, each one can be True or False, but at any one time only one button can be True:

Option button Value property

Here the OptNone option button has a value of False initially.  As soon as you select None as your milk choice - and thereby set the value of OptNone to True - the value of the other option buttons in the frame will automatically be set to False.


Adding Option Buttons using a Frame

There are two ways to add option buttons: either as part of a frame, or as part of an option group.  To add option buttons to a frame, first add the frame:

The Frame tool An empty frame on a form
Click on the Frame tool ... ... to add a frame

You can then click on the option button tool to add buttons to the frame one by one:

Click on the option button Click in the frame
Click on the option button ... ... then click inside the frame

It's a good idea to rename your option buttons once you've added them: I've called the ones above OptNone, OptSkimmed and OptNormal.

Adding Option Buttons in a Group

Option buttons don't have to belong to a group.  Instead, you can add the option buttons to a form, then set their GroupName property:

Option buttons selected on form

Select the option buttons to change their GroupName property (or you can set it for each button individually).

Setting GroupName property

Type in a value for the GroupName property (here we've set it to grpMilkChoices). Because no other option buttons use the same group name, the buttons will automatically now cancel each other when clicked.


There's no great advantage that I can think of to using a frame or using grouped buttons - maybe it's down to personal preference!

Coding Option Buttons

The code to manage option buttons can be a bit messy.  Here's our example code:

'transfer milk option into worksheet

'variable to hold name of milk choice

Dim MilkChoice As String

'determine which button was chosen

If Me.optNone Then

MilkChoice = "None"

ElseIf Me.optSkimmed Then

MilkChoice = "Skimmed"

ElseIf Me.optNormal Then

MilkChoice = "Normal"


MilkChoice = "N/A2"

End If

'transfer this into worksheet

ActiveCell.Offset(0, 4).Value = MilkChoice

Adding another option button is not only going to mess up the form, but also require more lines of code.  Like I say - combo boxes are easier! 


This blog has 0 threads Add post