Looping through checkboxes on userform

JimM

Well-known Member
Joined
Nov 11, 2003
Messages
752
I've hit another problem on my userform (I'm learning quickly though !)

I want to loop through certain checkboxes on a particular page of a multipage form. I've found out how to loop through controls and identify if it's a checkbox eg

Dim Cntr As Control
For Each Cntr In Me.Controls
If TypeOf Cntr Is MSForms.CheckBox Then

If Cntr.Value = True Then
coname = Cntr.Name

End If
End If

This works fine if I want to go through all the checkboxes but how do I loop through specific checkboxes only ie chkbx1 to chkbx5 only out a total of 8


Thanks

Jim
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
If they are all on the same page (say page 2):
Code:
    Dim ctl As MSForms.Control
    For Each ctl In Me.MultiPage1.Pages(1).Controls
        If TypeName(ctl) = "CheckBox" Then
            MsgBox ctl.Caption
        End If
    Next ctl

Note: it is better to use TypeName here since TypeOf will also accept togglebuttons and optionbuttons as checkboxes.
 
Upvote 0
use a select case statement
Code:
Select Case Right(Cntr.Name,1)
Case 1 to 5
     'do something
Case Else
     'do nothing
End Select
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,351
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top