Question : increasing Checkbox index in a loop

Hi, how I can solve issue like below, because this one doesn work.How I supose to connect CheckBox & boxgen ?

For boxgen = 1 To 10
    If CheckBox & boxgen = True Then
        Msgbox "work"
    End If
Next boxgen

Answer : increasing Checkbox index in a loop

Well you can do in two ways (at least)

1st - Using a for next increasing cycle

Dim s As Shape
Dim CheckBoxName As String
For x = 1 To 5
    CheckBoxName = "Check Box " & x
    Set s = Sheets("Sheet1").Shapes(CheckBoxName)
    If s.Type = msoFormControl Then
        If s.FormControlType = xlCheckBox Then
            s.OLEFormat.Object.Value = Checked
        End If
    End If
Next x

2nd - Using a for each cycle
Dim s As Shape
For Each s In Sheets("Sheet1").Shapes
    If s.Type = msoFormControl Then
        If s.FormControlType = xlCheckBox Then
            s.OLEFormat.Object.Value = Checked
        End If
    End If
Next

The second method is best because it's dificult (some times!) to know the right name of the shape. The only problem is that check all the checkboxes in the selected worksheet.

hope this helps
jpaulino
Random Solutions  
 
programming4us programming4us