Add OptionButtons in Excel

A

Andrew Lenczycki

Oli,

First, to have the two sets of two option buttons work as
two independant groups, you should put each of the two
option buttons inside a "frame" tool. This is the little
box with XYX at the top in the VBA toolbox. You can
change the name displayed on the frame by changing its
Caption property. You will need to display the
Properties window in VBA by pressing the F4 button. As
you select a component on your userform (say Frame1), the
properties window will display all the properties for
that particular control.

Second, you can change the captions of each of the option
buttons by selecting the particular option button on the
userform, then changing the Caption property again in the
Properties window. If the current caption is
OptionButton1, then double click on that name and type in
whatever you want it to be (ex: change the Caption
property from "OptionButton1" to "Add 10").

Third, you will need to provide the code to make each
option button do its thing. Below is a very simple
example for the code to make the first two option buttons
work (selecting option 1 will add 10 to whatever the
current cell value is, selecting option 2 will subtract
10 from the current cell value).


Private Sub OptionButton1_Click()
If OptionButton1 = True Then
ActiveCell.Value = ActiveCell.Value + 10
End If
End Sub

Private Sub OptionButton2_Click()
If OptionButton2 = True Then
ActiveCell.Value = ActiveCell.Value - 10
End If
End Sub

Hopefully this gives you some ideas. You can change the
code in each of the option buttons to cause the specific
action you desire (i.e. change "ActiveCell.Value =
ActiveCell.Value - 10" to whatever you need).

Andrew Lenczycki
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top