Excel VBA - UserForm OptionButton problem

M

murperi

I would like to have 5 groups of 2 OptionButtons on a UserForm for th
user to select units (i.e., inches or mm) for some measurements the
have entered and want to be able to tell the state of the optio
buttons on a worksheet.

I have grouped my OptionButtons into groups of two using the Group Nam
property.

I seem to have a problem with the state of the Option Buttons no
changing when I select them. For instance, if I have a group of tw
called in. and mm., and by default the in. button is selected, when
try to select the mm. button, the state of the in. button changes t
FALSE but the state of the mm. button stays FALSE too. When I clic
the mm. button a second time, it finally changes to TRUE. This proble
occurs when I use control source property of the Option Button to lin
it to a cell on my worksheet. If I don't use the control sourc
property, the Option Buttons work correctly and change state on th
first click but then I am left with the question of knowing the stat
of the buttons on my worksheet.

I have also tried VBA code something like:
Private Sub OptionButton1_Click()
OptionButton1.Value = True
OptionButton2.Value = False
End Sub
Private Sub OptionButton2_Click()
OptionButton2.Value = True
OptionButton1.Value = False
End Sub
but still have the problem of having to click the button twice for i
to change state.

Any help would be greatly appreciated!

Eri
 
D

Dave Peterson

It kind of sounds like you tried to group the two optionbuttons by using two
distinct groupnames for that group.

Each group of two buttons should have one unique name. Don't try to give each
optionbutton a different groupname within that group.

If you have 5 measurements, the groupnames could be meas1, meas2, meas3, meas4,
meas5.

But group meas1 would have a mm optionbutton and an in optionbutton.

(If I understood???)

Another option may be to just use a checkbox. (well 5 of them.)

__ Use Inches

then check it if you want inches--unchecked means mm's.
 
M

murperi

Dave,
Thanks for your reply. But in fact, I have only used 5 distinct grou
names, Group1 - Group5, each group having two option buttons
 
D

Dave Peterson

Ok, how about this?

You have each optionbutton in the group linked to the same controlsource cell.

Try a difference cell for each optionbutton.

(or use the checkbox????)
 
M

murperi

Already looked at that too and that wasn't it. I really need to use th
option buttons instead of the check box. I'm still trying to figure i
out
 
D

Dave Peterson

Just a wild guess...

Add some test code to show the value of the optionbuttons when you change them.
If the values change, but the display doesn't, then maybe it's a display
problem. (I don't think I've ever seen this, though.)

Maybe just adding:
me.Repaint
after your update would help.
 
R

Roy Miller

Did you ever suceed in sorting this, as I have exactly the same problem
all selections turn false on first click (even though I force one to b
true beforehand). After the first click it works perfectly. as i
should. They are all grouped together with the unique groupName and al
referenced to different controlSources, somewhat puzzled.

Nice to know what the solution was/is?

Ro
 

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