Hello! I have a lot of controls on a UserForm that are named in association with the column number they represent. For instance: TextBox1, TextBox2, TextBox3, etc. up to the 50's. Their are not only TextBoxes but also Labels and CheckBoxes that follow the same naming convention. All of my code relies on this naming convention when referencing the controls.
The other day i had a request for a new column A to be added to the sheet, resulting in me having to manually change the name property of every single control to be + 1 of what it currently was set at. My question is, if a column needs to be added anywhere on the sheet in-between current columns, how can i change all of the control names without manually going in and updating the properties (which takes a VERY long time). I tried creating a loop like this, but it doesn't work. The debug error i get is Run-time error 382: Could not set the name property. Can no set property at runtime.
Sub NameChange()
Dim ctrl As MSForms.control
For Each ctrl In UserForm2.MultiPage1.Pages(1).ConsentsFrame2.Controls
If ctrl.Name Like "Labelx*" Then
For A = 20 To 43
Select Case A
Case 20, 23, 25, 27, 29, 32, 34, 36, 39, 41, 43
ctrl.Name = "Labelx" & A
A = A + 1
End Select
Next
End If
Next
End Sub
Display More