I have a sheet where you click a button and then several ActiveX Checkboxes are created. The number depending on the values in some comboboxes but usually it's like 16-32.
If you click the button again they are deleted and new ones are created in their place. It works fine the first couples of times, all the checkboxes are deleted and new ones appear. But after pressing it like 20-30 times it kinda freezes and Excel restarts.
After the restart it works again but only once, the second time you press it Excel freezes and restarts again. Then it works again but only once, then it restarts again and so on.
If you wait a couple of minutes it works again and you can press it over and over, but after like 20-30 presses it freezes again and the whole thing repeats.
This is the code that deletes the checkboxes:
Dim s As Shape
For Each s In Sheets("Choice").Shapes
If s.Type = 12 Then
If Not Intersect(s.TopLeftCell, Sheets("Choice").Range("A14:T100")) Is Nothing Then
s.Delete
End If
End If
Next
The code that creates them:
for i = 1 to Ubound(EmpList)
'lots of code that creates the variables offset and col
Set rng = Choice.Cells(14 + (i * 2) - offset, col)
cellLeft = rng.Left
cellTop = rng.Top
cellwidth = rng.Width
cellheight = rng.Height
Set obj = ActiveSheet.OLEObjects.Add(ClassType:="Forms.Checkbox.1", Left:=cellLeft, Top:=cellTop, Width:=cellwidth * 2, Height:=cellheight * 2)
obj.Name = "CheckBox" & i
ActiveSheet.OLEObjects("CheckBox" & i).Object.Value = False
ActiveSheet.OLEObjects("CheckBox" & i).Object.Caption = EmpList(i - 1)
Next i
Anyone knows what might be wrong?