select shapes based on checkboxes at the click of a button

mukuldhingra

New Member
Joined
Jan 29, 2014
Messages
4
Hi,

I am a newbie. I have a worksheet with 5 box shapes (Box 1, Box 2 ....) and 5 checkboxes (Check1, Check2, ....). What I want now is based on the check boxes I have selected the corresponding boxes should get selected on the click of a button.

The code I have written is:

Code:
Sub CSelect()

Dim C As Integer
Dim B As Long

For C = 1 To 5
For istateloop = 1 To 5
 

If ActiveSheet.OLEObjects("Check" & C).Object.Value = True Then
ActiveSheet.Shapes.Range(Array("Box " & B)).Select
End If
Next

Next C

End Sub



When I run this code only the 5th box gets selected.

Please let me know where I am going wrong
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Welcome to MrExcel.

Why do you have two loops there? And what is the purpose of the variable B, to which nothing has been assigned?

If you select a single object previous selections are unselected. You need to create an array of all the objects to be selected.
 
Upvote 0
Hi Andrew,

Apologies... that 'B' is actually istateloop which i forgot to sanitize while posting this query... what I want to do is .. i have multip[le shapes on my worksheet and have similar number of checkboxes... i need to write a code, where user selects the 1 or multiple checkboxes and once he clicks OK button after selected checkboxes.. relevant shapes should get selected..
 
Upvote 0
See if you can adapt this example:

Code:
Sub Test()
    Dim i As Long
    Dim j As Long
    Dim List() As String
    With ActiveSheet
        For i = 1 To 5
            If .OLEObjects("CheckBox" & i).Object.Value = True Then
                j = j + 1
                ReDim Preserve List(1 To j)
                List(j) = "Rectangle " & i
            End If
        Next i
        .Shapes.Range(List).Select
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,194
Members
449,072
Latest member
DW Draft

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