Find and rename every second and third checkbox

natkatten

New Member
Joined
May 20, 2011
Messages
5
I have about 200 checkboxes (Form Controls) on a worksheet. They all have the same description. Let's just say that they are all named "Text1". Now I want every second checkbox to have the description "Text2", while every third has the description "Text3". Text1, Text2, Text3, Text1, Text2, Text3 and so on to the last checkbox.


How do I create a loop that can accomplish this?


Thanks in advance for your help.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi. You could try the following (adapted from a previous thread):

Code:
Sub UpdateChkBoxes()
Dim cb As CheckBox
Dim cbValue As Integer
Dim sht As Worksheet
Set sht = ThisWorkbook.Sheets("Sheet1")
cbValue = 1
With sht
    For Each cb In sht.CheckBoxes
        cb.Caption = "Text " & cbValue
        cbValue = cbValue + 1
        If cbValue > 3 Then cbValue = 1
    Next
End With
End Sub

hth
 
Upvote 0
Thanks. This works really well with my example. BUT - and this is my mistake when I made the example - in my worksheet the real text is not as shown. It is different descriptions. Aka. "DK", "SE", "NO". So I want the checkboxes to show DK, SE, NO, DK, SE, NO and so on.
 
Upvote 0
One way would be to put a select case statement in, for example:

Code:
Sub UpdateChkBoxes3()
Dim cb As CheckBox
Dim cbValue As Integer
Dim sht As Worksheet
Set sht = ThisWorkbook.Sheets("Sheet1")
cbValue = 1
With sht
    For Each cb In sht.CheckBoxes
        Select Case cbValue
        Case 1
            cb.Caption = "DK"
        Case 2
            cb.Caption = "SE"
        Case 3
            cb.Caption = "NO"
        End Select
        cbValue = cbValue + 1
        If cbValue > 3 Then cbValue = 1
    Next
End With
End Sub

And adapt to your requirements.
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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