For...Loop to verify at least one checkbox = True

R

RyanH

I have a UserForm with a Multipage Control (mpgPaint). Each Page is Named
pgColor1, pgColor2, pgColor3, pgColor4, pgColor5, & pgColor6. On each page
there are two checkboxes named chk1stSurfaceP1 & chk2ndSurfaceP1 (the number
1 represents what page it is on). How can I cycle through each page and make
sure at least 1 checkbox is true? This is what I have, but it does not seem
to work.

Dim i As Byte

If chkPaint.Value = True Then
Do
For i = 1 To 5
If mpgPaint.Pages(i - 1).CheckBox("chk1stSurfaceP" &
i).Value = False And _
mpgPaint.Pages(i - 1).CheckBox("chk2ndSurfaceP" &
i).Value = False Then
MsgBox ("You forgot to specify 1st or 2nd
Surface in Paint Color " & i & "."), vbCritical
StopCode = True
Exit For
End If
Next i
Loop Until mpgPaint.Pages(i - 1).Visible = False
End If

Thanks in Advance,
Ryan
 
B

Bernie Deitrick

Ryan,

Dim i As Byte

If chkPaint.Value = True Then
For i = 1 To 2
If Controls("chk1stSurfaceP" & i).Value = False And _
Controls("chk2ndSurfaceP" & i).Value = False Then
MsgBox ("You forgot to specify 1st or 2nd Surface in Paint Color " & i & "."), vbCritical
GoTo NotChecked
End If
Next i
End If

MsgBox "You checked the surfaces correctly."
Exit Sub
NotChecked:

HTH,
Bernie
MS Excel MVP
 
B

Bernie Deitrick

Oops.. I forgot to change

For i = 1 To 2

back to

For i = 1 To 6

HTH,
Bernie
MS Excel MVP
 

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