InsatiableAmos
New Member
- Joined
- Jan 7, 2010
- Messages
- 8
I have some VBA (using Excel 2007) that deletes and re-creates a bunch (20-ish) checkboxes in a spreadsheet. Since i'm using the controls-based checkboxes, Excel defaults them to object names of "CheckBox1, CheckBox2, CheckBox3, etc" as I create them the first time around.
Later on, i clear all checkboxes and implement the SAME checkbox-creating code to re-create all or some of the checkboxes, but Excel doesn't number them in order the second time around! I end up with something like "CheckBox2, CheckBox19, CheckBox3, CheckBox12, etc."
What could be causing my code to create things out of order the second time around? Is there a way to reset Excel's Checkbox-numbering iterator?
The code i'm using to create checkboxes is:
And the code i'm using to delete my checkboxes is:
Later on, i clear all checkboxes and implement the SAME checkbox-creating code to re-create all or some of the checkboxes, but Excel doesn't number them in order the second time around! I end up with something like "CheckBox2, CheckBox19, CheckBox3, CheckBox12, etc."
What could be causing my code to create things out of order the second time around? Is there a way to reset Excel's Checkbox-numbering iterator?
The code i'm using to create checkboxes is:
Code:
Dim x As Long
Dim BoxCell As String
BoxCell = ""
x = 0
'j gets passed into the sub as a "Long" somewhere between the values of 5 and 35
Do While x < j
BoxCell = "C" & x * 4 + 13
With Range(BoxCell)
l = .Left
t = .Top
End With
ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1", Link:=False, _
DisplayAsIcon:=False, Left:=l, Top:=t, Width:=100, Height:= _
16).Select
With Selection
.LinkedCell = BoxCell
End With
x = x + 1
Loop
Code:
Dim myObj As Object
CountDels = 0
For Each myObj In ActiveSheet.OLEObjects
If InStr(1, myObj.Name, "CheckBox", vbTextCompare) Then
myObj.Delete
End If
Next myObj
Last edited: