ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Counting OptionButtons (https://www.excelbanter.com/excel-programming/432443-counting-optionbuttons.html)

Patrick C. Simonds

Counting OptionButtons
 
I have 11 identical groups of OptionButtons each group consists of 6
OpTionButtons. Each group has its own groupname. Is there any way to count
how many of OptionButton4's have a True value?


Matthew Herbert

Counting OptionButtons
 
On Aug 14, 5:55*pm, "Patrick C. Simonds"
wrote:
I have 11 identical groups of OptionButtons each group consists of 6
OpTionButtons. Each group has its own groupname. Is there any way to count
how many of OptionButton4's have a True value?


Patrick,

Some sample code is below. I haven't tested it, but it should work.
I'm assuming your user form is UserForm1 and the target frame is
Frame1. Of course, you can adjust the user form and frame as needed.

Best,

Matthew Herbert

Dim Ctrl As MSForms.Control
Dim intCnt As Integer

For Each Ctrl In UserForm1.Frame1.Controls
If TypeOf Ctrl Is MSForms.OptionButton Then
If Ctrl.Value = True Then
intCnt = intCnt + 1
End If
End If
Next Ctrl

MsgBox "The number of true values in the specified " & vbLf & _
"form and frame is " & intCnt & "."

Rick Rothstein

Counting OptionButtons
 
You are going to have to clarify what you mean by "count how many of
OptionButton4's have a True Value"... only one control on a UserForm can
have the name OptionButton4; and, if you mean OptionButton4 is the GroupName
you want to check, then only one control within that GroupName collection
can be True at any given time.

--
Rick (MVP - Excel)


"Patrick C. Simonds" wrote in message
...
I have 11 identical groups of OptionButtons each group consists of 6
OpTionButtons. Each group has its own groupname. Is there any way to count
how many of OptionButton4's have a True value?




All times are GMT +1. The time now is 05:55 PM.

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