Bomino
Member
Hi
I have a userform where all the Labels and TextBoxes are created at Run Time. I got pretty much everything set up correctly except for the most important part: Transferring textboxes data from Userform to the worksheet.
For some reasons, the code for the CommandButton1 keeps giving me an error message:
"Object doesn't support this property or method"
Could someone please help?
See the entire Userform code below and I am also attaching the file.
I have a userform where all the Labels and TextBoxes are created at Run Time. I got pretty much everything set up correctly except for the most important part: Transferring textboxes data from Userform to the worksheet.
For some reasons, the code for the CommandButton1 keeps giving me an error message:
"Object doesn't support this property or method"
Could someone please help?
See the entire Userform code below and I am also attaching the file.
Code:
Dim numbertxt As Long
Private Sub UserForm_Initialize()
Dim i As Long
numbertxt = Application.CountA(ShtMyGrades.[A:A])
Dim lblL1 As Control
For i = 2 To numbertxt
Set lblL1 = Controls.Add("Forms.Label.1")
With lblL1
.Caption = “Label” & i
.Name = “lbl” & i
.Height = 20
.Width = 50
.Left = 20
.Top = 20 * i * 1
End With
Next i
Dim q As Long
For q = 2 To numbertxt
Controls(“lbl” & q) = Cells(q, 1)
Next q
Dim txtB1 As Control
For i = 2 To numbertxt
Set txtB1 = Controls.Add("Forms.TextBox.1")
With txtB1
.Name = “TxtBox” & i
.Height = 20
.Width = 50
.Left = 70
.Top = 20 * i * 1
End With
Next i
End Sub
Private Sub CommandButton1_Click()
Dim p As Long
For p = 2 To numbertxt
ShtMyGrades.Cells(p, 5) = Controls(“TxtBox” & p).Text
Next p
End Sub
Private Sub CommandButton3_Click()
Dim ctl As Control
For Each ctl In Me.Controls
If TypeName(ctl) = “TextBox” Then
ctl.Value = “”
End If
Next ctl
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub