dotrongtrung
New Member
- Joined
- Jan 14, 2017
- Messages
- 2
Hi. I'm new to VBA and I dont know how to take action with the Userform here.
I have a userform which allows users add more textboxes and type the value to the textboxes. I want to copy those values from each additional textbox to separate cells. This is what I did, but not working.
"Add textbox after clicking_THIS ONE IS WORKING"
Private Sub CommandButton2_Click()
x = Me.Controls.count + 1
Set xx = Controls.Add("Forms.TextBox.1", "CtrlName" & x)
xx.Top = x * 20 - 108
xx.Left = 396
xx.Width = 288
End Sub
"Get value from textboxes to cell_THIS IS NOT WORKING"
Private Sub CommandButton1_Click()
Dim count as Integer
Dim i as Integer
count = Me.Controls.count - 9 ("I have 9 other controls, so need to - 9 to count the number of textboxes")
For i = 1 To count
Cells(i, 1).Select
ActiveCell.Value = Me.Controls("TextBox" & i).Value
Next i
End Sub
The problem is the Me.Controls("TextBox" & i).Value. I tried different funtions here, but still couldnt solve that. Can anyone help me with this. Thanks alot.
I have a userform which allows users add more textboxes and type the value to the textboxes. I want to copy those values from each additional textbox to separate cells. This is what I did, but not working.
"Add textbox after clicking_THIS ONE IS WORKING"
Private Sub CommandButton2_Click()
x = Me.Controls.count + 1
Set xx = Controls.Add("Forms.TextBox.1", "CtrlName" & x)
xx.Top = x * 20 - 108
xx.Left = 396
xx.Width = 288
End Sub
"Get value from textboxes to cell_THIS IS NOT WORKING"
Private Sub CommandButton1_Click()
Dim count as Integer
Dim i as Integer
count = Me.Controls.count - 9 ("I have 9 other controls, so need to - 9 to count the number of textboxes")
For i = 1 To count
Cells(i, 1).Select
ActiveCell.Value = Me.Controls("TextBox" & i).Value
Next i
End Sub
The problem is the Me.Controls("TextBox" & i).Value. I tried different funtions here, but still couldnt solve that. Can anyone help me with this. Thanks alot.