I have a worksheet that contains many checkboxes. Excel names these automatically as CheckBox1, CheckBox2, etc... However, for my document, I need to rename them all as Rij11_1, Rij11_2, etc (Rij11 being row 11, _1 being the first checkbox in that row, and so on). It is important that the renaming starts on _1 for each row.
Stackoverflow members Osknows and Dave DuPlantis helped me already on this one (THANKS A LOT FOR ALL YOUR HELP SO FAR), with this code:
Sub test()
Dim obj As OLEObject, ChkBoxRow as long
ChkBoxRow = 11
With Worksteets("Storia")
For Each obj In .OLEObjects
If TypeName(obj.Object) = "CheckBox" Then
if obj.TopLeftCell.Row = ChkBoxRow then
obj.Name = "Rij11_" & Right(obj.Name, 1)
end if
End If
Next obj
End With
End Sub
However, the first renamed checkbox on each row does not start on 1 (usually on 7, for some reason which escapes me), and if there are more than 10 checkboxes in a row, the numbering doesn't go beyond 10. After _9, I get _0 instead of _10 and then, after _0, it continues with _1 again, resulting in name duplicates in the row.
Is there anyone who can help me out with this renumbering issue?
Thanks a lot!
Kind regards, Marc