B
Bill D.
I need to rename checkboxes on a worksheet IN THE ORDER IN WHICH THE
APPEAR ON THE WORKSHEET. That is the first box at the top will be number
1 the second number 2 and so on.
As I have developed the worksheet layout I have added and removed shape
objects (checkboxes and optionbuttons) so that now the internal
numbering of the objects is no longer sequential from the top down.
I presently use the following two procedures to determine the number of
objects on the worksheet and then rename them based on the type. This
will yield, for example checkbox1, etc.
Sub GetShapeName()
On Error Resume Next
For i = 1 To ActiveSheet.Shapes.Count
With ActiveSheet
ShNm = .Shapes(i).Name
End With
Next i
End Sub
Sub NameTBs()'<=== Change form type and name as needed
x = 0
On Error Resume Next
For i = 1 To ActiveSheet.Shapes.Count
With ActiveSheet
If .Shapes(i).Type = msoFormControl Then
If .Shapes(i).FormControlType = xlCheckBox Then
x = x + 1
.Shapes(i).Name = "checkbox" & x
End If
End If
End With
Next i
End Sub
This works well except the renaming is based on the internal numbering
of the object which is not the same as the physcial location of the
object on the sheet. So, based on physical location, I end up with
something like:
checkbox1
checkbox2
checkbox38
checkbox3
checkbox24
Is there a way to rename the objects based on position from the top of
the sheet? is zorder what I need to use?
I hope this explanation is clear.
Thanks
Bill
There are 10 types of people in the world. Those that understand binary
and those that don't.
APPEAR ON THE WORKSHEET. That is the first box at the top will be number
1 the second number 2 and so on.
As I have developed the worksheet layout I have added and removed shape
objects (checkboxes and optionbuttons) so that now the internal
numbering of the objects is no longer sequential from the top down.
I presently use the following two procedures to determine the number of
objects on the worksheet and then rename them based on the type. This
will yield, for example checkbox1, etc.
Sub GetShapeName()
On Error Resume Next
For i = 1 To ActiveSheet.Shapes.Count
With ActiveSheet
ShNm = .Shapes(i).Name
End With
Next i
End Sub
Sub NameTBs()'<=== Change form type and name as needed
x = 0
On Error Resume Next
For i = 1 To ActiveSheet.Shapes.Count
With ActiveSheet
If .Shapes(i).Type = msoFormControl Then
If .Shapes(i).FormControlType = xlCheckBox Then
x = x + 1
.Shapes(i).Name = "checkbox" & x
End If
End If
End With
Next i
End Sub
This works well except the renaming is based on the internal numbering
of the object which is not the same as the physcial location of the
object on the sheet. So, based on physical location, I end up with
something like:
checkbox1
checkbox2
checkbox38
checkbox3
checkbox24
Is there a way to rename the objects based on position from the top of
the sheet? is zorder what I need to use?
I hope this explanation is clear.
Thanks
Bill
There are 10 types of people in the world. Those that understand binary
and those that don't.