Pianoman23
New Member
- Joined
- May 16, 2014
- Messages
- 25
Can anyone help? I'm using the following code to create and populate textboxes on a userform:
This routine is repeated for the months of May, June, July, and so on.
Is there a code that will remove/delete all of the textbox controls previously created in one go?
Code:
Dim ct As Integer
Dim txtB1 As Control
Dim lbl1 As Control
Dim r As Integer 'Database Row
Dim c As Integer 'Database Column
Dim t As Integer 'Top Position on screen
Dim l As Integer 'Left Position on screen
ct = Sheets("Database").Range("C18") 'Counts number of Branches on Database
'APRIL
'Create Textboxes
r = 20
c = 4
t = 84
l = 87
For i = 1 To ct
Set txtB1 = Controls.Add("Forms.TextBox.1")
With txtB1
.Name = "chkDemo" & i
.Text = Sheets("database").Cells(r, c)
.Height = 18
.Width = 50
.Left = l
.Top = t
End With
c = c + 4
t = t + 20
Next i
Set txtB1 = Controls.Add("Forms.TextBox.1")
With txtB1
.Name = "chkDemo" & i
.Text = Sheets("Summary").Range("D2")
.Height = 18
.Width = 50
.Left = l
.Top = t + 30
End With
Set txtB1 = Controls.Add("Forms.TextBox.1")
With txtB1
.Name = "chkDemo" & i
.Text = Sheets("Summary").Range("B2")
.Height = 18
.Width = 50
.Left = l
.Top = t + 50
End With
Set txtB1 = Controls.Add("Forms.TextBox.1")
With txtB1
.Name = "chkDemo" & i
.Text = Sheets("Summary").Range("F2")
.Height = 18
.Width = 50
.Left = l
.Top = t + 70
End With
Set txtB1 = Controls.Add("Forms.TextBox.1")
With txtB1
.Name = "chkDemo" & i
.Text = Format(Sheets("Summary").Range("I2"), "Percent")
.Height = 18
.Width = 50
.Left = l
.Top = t + 90
End With
tbYTDa.Value = Worksheets("Summary").Range("H2")
tbYTDl.Value = Worksheets("Summary").Range("G2")
tbYTDpercent.Value = Format(Worksheets("Summary").Range("M2"), "Percent")
End If
Is there a code that will remove/delete all of the textbox controls previously created in one go?
Last edited by a moderator: