Counting OptionButtons

P

Patrick C. Simonds

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?
 
M

Matthew Herbert

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 & "."
 
R

Rick Rothstein

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.
 

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