Excel VBA and Option Buttons
Excel VBA and Option Buttons
http://www.homeandlearn.org/code_for_vba_option_buttons.html
1/4
4/7/2015
So that your buttons are treated as a group, return to your form in the VBA Editor and click on the YES
option button. Now have a look at the properties for the button. Locate the GroupName property and
type OB1. Press the enter key on your keyboard and do the same for the NO option button. Both
buttons will then have a value of OB1 for their GroupName property (OB1 is just something we came
up with - you can call your group of option buttons anything you like.):
Go back to your coding window and create a new Private Sub. Call it GetOptionButtonValue. What
we need to do, here, is to get the value from Column 7 on our spreadsheet (the G Column). We'll then
use an If Statement to test this value. Here's the full code for this new Sub:
http://www.homeandlearn.org/code_for_vba_option_buttons.html
2/4
4/7/2015
http://www.homeandlearn.org/code_for_vba_option_buttons.html
3/4
4/7/2015
You can test it out again. Run your form and click the Load Image Information button. You should find
that the correct option button is selected for the Flash item.
We can now load an image into the image box. We'll do that in the next lesson below.
http://www.homeandlearn.org/code_for_vba_option_buttons.html
4/4