View Single Post
  #13   Report Post  
Posted to microsoft.public.excel.misc
formatting formatting is offline
external usenet poster
 
Posts: 10
Default How do I activate an option button?

I am missing something. Let me start from the beginning.

1. Open a new book
2. Insert Option Button from Control Toolbox. I name it OptionButton1 and
place it in cells D19-E20
3. Insert a second Option Button from Control Toolbox. OptionButton2 in
cells D23-E24
4. Repeat step 3 for a third OptionButton3 in cells D27-E28
5. Go to OptionButton1, Right Click and under View Code, insert code:
"Range("B8").Value = 1"
6. Go to OptionButton2, Right Click and under View Code, insert code:
"Range("B8").Value = 2"
7. Go to OptionButton3, Right Click and under View Code, insert code:
"Range("B8").Value = 3"

What do I do next to be able to select either OptionButton1, 2 or 3?


"Rick Rothstein" wrote:

So it is clear that what Gord suggested is what you did, you should have the
following code (I used your control names rather than the default control
name that Gord used in his example; and note that, contrary to your posting,
your control names cannot have a space character in them)...

Private Sub Option1_Click()
Range("B8").Value = 1
End Sub

Private Sub Option2_Click()
Range("B8").Value = 2
End Sub

Private Sub Option3_Click()
Range("B8").Value = 3
End Sub

Private Sub Option4_Click()
Range("B8").Value = 4
End Sub

And this code needs to be located in the code window for the worksheet where
your OptionButtons are located.

--
Rick (MVP - Excel)


"Formatting" wrote in message
...
What do I need to do after I revise the code for each button? Revising the
code as suggested by itself does not do anything.

"Gord Dibben" wrote:

Private Sub OptionButton1_Click()
Range("B8").Value = 1
End Sub

Revise code for each of buttons 2 through 4


Gord Dibben MS Excel MVP


On Mon, 16 Mar 2009 12:08:30 -0700, Option Button <Option
wrote:

Let assume I have created 4 option buttons (from the control toolbox)
and I
have named them as option1, option 2, option 3, and option 4
Let also assume that option 1 occupies cells D8 to F9, option 2 occupies
cells D12 to F13, option 3 in cells J8 to J9, and option 4 in cells J12
to J13
In cell B8, I want it to be equal to 1 if option 1 is selected, equal to
2
if option 2 is selected, 3 if option 3 is selected and 5 if option 4 is
selected
1. How do I activate an option button so that I can select either option
1,
2, 3 or 4? (If one option is selected, then the rest should be blank)
2. When one of the option is selected, how do assign my cell B8 with the
correct number?