How to extract multiple textbox values in userform to excel sheet through VBA using a for loop

arunmohanae

New Member
Joined
Jul 12, 2016
Messages
2
Dear all,

How I can extract multiple text box values in a userform to an excel sheet through a VBA for loop. VBA script is written below. ("tb_Model" & i portion is having error)

1. Tbl_Orders is an excel table
2. tb_Model1, tb_Model2, tb_Model3, tb_Model4 and tb_Model5 are text boxes in userform



Public Sub SAVE_TO_LOG_BUTTON_Click()
Dim i As Integer
i = 1
Dim LASTROW As Long
LASTROW = ActiveWorkbook.Worksheets("Orders_and_Inventory").ListObjects("Tbl_Orders").ListRows.Count
For i = 1 To 5
If "tb_Model" & i <> "" Then
ActiveWorkbook.Worksheets("Orders_and_Inventory").ListObjects("Tbl_Orders").DataBodyRange(LASTROW + i, 6).Value = "tb_Model" & i.Value

End If
Next i
End Sub
 

Some videos you may like

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

wideboydixon

Well-known Member
Joined
Jun 2, 2016
Messages
3,401
Try changing this:

Code:
"tb_Model" & i
To this:

Code:
Controls("tb_Model" & i).Value
WBD
 

Watch MrExcel Video

Forum statistics

Threads
1,099,568
Messages
5,469,457
Members
406,653
Latest member
CBeeker

This Week's Hot Topics

Top