RAYLWARD102
Well-known Member
- Joined
- May 27, 2010
- Messages
- 529
I've been adding dynamic buttons using some code like this:
Works great...Later on in my code, I want to clear the slate....I've been doing it with...
My problem is that it works...and then stops working after some time. It seems that some of the controls are missed when being removed and when the new controls show up, they have some old ones kicking about. Any idea's how I can get rid of those pesky controls in a reliable fashion?
Code:
Private Sub UserForm_Initialize()
Set collect3 = New Collection
Set ws = Sheets("sheets1")
iRow = (ws.Cells(Rows.Count, c3).End(xlUp).Row + 2)
butset = 3
butPERrow = 5
butRows = "0"
butH = 50
butW = 180
buTop = (butH + 1)
buLft = (butW + 1)
i = "0"
For Each cell In ws.Range("a1:a" & iRow).Cells
Set ctr = UserForm1.Frame3.Controls.Add("Forms.CommandButton.1")
ctr.Caption = cell.Value
ctr.Font.Size = 17
ctr.BackStyle = 1
ctr.TabStop = False
ctr.Font.Name = "Arial"
ctr.Font.Bold = True
ctr.WordWrap = True
ctr.Name = cell.Value
ctr.Height = butH
ctr.Width = butW
If i = butPERrow Then
butRows = butRows + 1
i = "0"
End If
ctr.Top = buTop * butRows
ctr.Left = buLft * i
Set ct3 = New Class3
Set ct3.Group3 = ctr
collect3.Add Item:=ct3, Key:=ctr.Name
i = i + 1
nextitem:
Next cell
end sub
Works great...Later on in my code, I want to clear the slate....I've been doing it with...
Code:
For Each ct3 In collect3
UserForm1.Frame3.Controls.Remove ct3.Group3.Name
Next ct3
Set collect3 = New Collection
My problem is that it works...and then stops working after some time. It seems that some of the controls are missed when being removed and when the new controls show up, they have some old ones kicking about. Any idea's how I can get rid of those pesky controls in a reliable fashion?