Hi!
This is my first post, so I hope someone can help a newbie like me
I have a simple userform with over 50 textboxes, named TextBox1, TextBox2, TextBox3 etc.....50.
I want the values (as string) of these textboxes back into my excel sheet.
Is there a way of using loops instead of manually defining every textbox?
Instead of:
'ActiveCell.Offset(0, 1).Select
'ActiveCell = UserForm1.TextBox1
'ActiveCell.Offset(0, 1).Select
'ActiveCell = UserForm1.TextBox2
'ActiveCell.Offset(0, 1).Select
'ActiveCell = UserForm1.TextBox3
and so on and so on....
This is how far I've gotten:
Dim ctrl As Object
Dim NextTextBox As Object
Dim Counter As Integer
Dim TextBox As Object
Counter = 0
TextBoxLoop:
Counter = Counter + 1
If Counter < 6 Then
NextTextBox = "UserForm1.TextBox" & Counter
ActiveCell.Offset(0, 1).Select
ActiveCell = "UserForm1.TextBox" & Counter ' Returns only the name of the textbox I want the values from. How to I get the values in the worksheet in Excel?
GoTo TextBoxLoop
End If
But this it only returns the Textbox-name in the cell instead for the actual content of the TextBox.
I know this is probably way of, but when I have managed to get a variable to be called the same as the name of the textbox I want values from...
Please don't let me manually go through 50 textboxes
Will be happy for any reply!
This is my first post, so I hope someone can help a newbie like me
I have a simple userform with over 50 textboxes, named TextBox1, TextBox2, TextBox3 etc.....50.
I want the values (as string) of these textboxes back into my excel sheet.
Is there a way of using loops instead of manually defining every textbox?
Instead of:
'ActiveCell.Offset(0, 1).Select
'ActiveCell = UserForm1.TextBox1
'ActiveCell.Offset(0, 1).Select
'ActiveCell = UserForm1.TextBox2
'ActiveCell.Offset(0, 1).Select
'ActiveCell = UserForm1.TextBox3
and so on and so on....
This is how far I've gotten:
Dim ctrl As Object
Dim NextTextBox As Object
Dim Counter As Integer
Dim TextBox As Object
Counter = 0
TextBoxLoop:
Counter = Counter + 1
If Counter < 6 Then
NextTextBox = "UserForm1.TextBox" & Counter
ActiveCell.Offset(0, 1).Select
ActiveCell = "UserForm1.TextBox" & Counter ' Returns only the name of the textbox I want the values from. How to I get the values in the worksheet in Excel?
GoTo TextBoxLoop
End If
But this it only returns the Textbox-name in the cell instead for the actual content of the TextBox.
I know this is probably way of, but when I have managed to get a variable to be called the same as the name of the textbox I want values from...
Please don't let me manually go through 50 textboxes
Will be happy for any reply!