How do I create a option group in forms coding

D

Dave

Excel 2003

example: If Gender was a question on an excel form - how do I code it to
only allow one selection from the 2 choices?

Thanks

Dave
 
D

Dave Peterson

On a userform?
You could put both optionbuttons inside a frame.

Or maybe you could use a single checkbox (label it male (or female)). If it's
checked, the gender is what the label shows.
 
D

Dave

Thanks for the reply.
Yes on a userform.
I have added the frame and necessary option buttons to the form.
I have given the frame a name.
However I can not seem to store the value of the choice.

I am not even sure I have given values to each option. I am assuming they
are by default 1,2,3

If not how do I give values to the options?

Dave
 
D

Dave Peterson

Just check to see which is chosen:

Dim IsMale As Boolean

If Me.OptionButton1.Value = False _
And Me.OptionButton2.Value = False Then
'neither selected, what should happen
ElseIf Me.OptionButton1.Value = True Then
IsMale = True
ElseIf Me.OptionButton2.Value = True Then
IsMale = False
End If
 
D

Dave

I am trying to dump the choice into a worksheet (and/or) populate the option
from what may already exist on a worksheet..

If my Option Frame has 3 choices would this be three cells or one cell?

Dave
 
D

Dave Peterson

If the frame has three choices, you can look at each commandbutton:

dim myCell as range
set mycell = worksheets("Sheet999").range("A1")
if me.optionbutton1.value = true then
mycell.value = "Male"
elseif me.optionbutton2.value = true then
mycell.value = "Female"
elseif me.optionbutton3.value = true then
mycell.value = "Wouldn't say"
else
mycell.value = "none chosen"
end if



I am trying to dump the choice into a worksheet (and/or) populate the option
from what may already exist on a worksheet..

If my Option Frame has 3 choices would this be three cells or one cell?

Dave
 

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