ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   So many option buttons (https://www.excelbanter.com/excel-programming/345431-so-many-option-buttons.html)

Rmagic[_3_]

So many option buttons
 

hello again

I have a form with 31 option buttons (for different colours) and
command button

How do i send which option button (which number) has been selected to
sheet cell from the command button only 1 selection is poss

Thank yo

--
Rmagi
-----------------------------------------------------------------------
Rmagic's Profile: http://www.excelforum.com/member.php...fo&userid=2859
View this thread: http://www.excelforum.com/showthread.php?threadid=48451


Leith Ross[_261_]

So many option buttons
 

Hello Rmagic,

The easiest way is to first find the OptionButton that was selecte
using a loop.
This code will place the OptionButton number in cell "A1". You ca
change the cell to what you need as well as the max loop value of 31
This code assumes all the OptionButton numbers are sequential.


Code
-------------------

Dim OB As Object

For I = 1 To 31
Set OB = Controls("OptionButton" & I)
If OB.Value = True Then
Range("A1").Value = I
Exit Loop
End If
Next I

-------------------

Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=48451


Norman Jones

So many option buttons
 
Hi Leith,

Exit Loop


I am sure you intended:

Exit For


---
Regards,
Norman



"Leith Ross" wrote
in message ...

Hello Rmagic,

The easiest way is to first find the OptionButton that was selected
using a loop.
This code will place the OptionButton number in cell "A1". You can
change the cell to what you need as well as the max loop value of 31.
This code assumes all the OptionButton numbers are sequential.


Code:
--------------------

Dim OB As Object

For I = 1 To 31
Set OB = Controls("OptionButton" & I)
If OB.Value = True Then
Range("A1").Value = I
Exit Loop
End If
Next I

--------------------

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile:
http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=484513




Rmagic[_4_]

So many option buttons
 

Thanks for the help

i will give it a g

--
Rmagi
-----------------------------------------------------------------------
Rmagic's Profile: http://www.excelforum.com/member.php...fo&userid=2859
View this thread: http://www.excelforum.com/showthread.php?threadid=48451


Leith Ross[_262_]

So many option buttons
 

Hello Norman,

Thanks for catching that mistake. I'm sure Rmagic appreciates it a
well.

Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=48451


Bob Phillips[_6_]

So many option buttons
 
Assuming that the optionbuttons are from the forms toolbar, if you select
them all and link them to a cell (right-click, Format ControlControl, cell
link), then that cell will contain an index number that you can use in code
or in worksheet functions.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Leith Ross" wrote
in message ...

Hello Rmagic,

The easiest way is to first find the OptionButton that was selected
using a loop.
This code will place the OptionButton number in cell "A1". You can
change the cell to what you need as well as the max loop value of 31.
This code assumes all the OptionButton numbers are sequential.


Code:
--------------------

Dim OB As Object

For I = 1 To 31
Set OB = Controls("OptionButton" & I)
If OB.Value = True Then
Range("A1").Value = I
Exit Loop
End If
Next I

--------------------

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile:

http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=484513





All times are GMT +1. The time now is 12:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com