Using a loop with several check boxes?

450nick

Well-known Member
Joined
May 11, 2009
Messages
507
Hi all,

I have a loop function I'm writing and I want it to look through several text entry boxes in a userform. The boxes are names Race1, Race2, Race3 etc

I want to vary the box I'm looking at using a variable called Ra. Below is a sample line:

If Not Me.Race & Ra.Value = "" Then

This doesn't work but I'm not sure how to make it so the code 'sees' Race1 instead of Race & Ra. Any ideas?

Thanks!
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Something like this:
Code:
    For intX = 0 To Me.Controls.Count - 1
        If Me.Controls(intX).Name = "Race" & Ra Then
            If Me.Controls(intX).Value = True Then
                 'do stuff
            End If
        End If
    Next
 
Upvote 0
Thanks for the reply, that works great. I would still like to be able to refer to them in the manner I described above if possible though..? I would like the macro in some instances to use the data from the next box as well, so I'll need it to be able to refer to "Race" & Ra and "Race" & Ra + 1 for example.
 
Upvote 0
Instead of:-
Code:
Me.Race & Ra.Value
you need to do this:-
Code:
Me.Controls("Race" & Ra).Value

So for example:-
Code:
If Me.Controls("Race" & [COLOR=red][B]Ra[/B][/COLOR]).Value = Me.Controls("Race" & [COLOR=red][B]Ra+1[/B][/COLOR]).Value Then
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,815
Members
452,946
Latest member
JoseDavid

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