I have an userform to input data into my Excel table (Table8) and I am currently using the below code to move the data from the UserForm to the table. Is there a way that I can move the data into the relevant location in the table by using the header name for each column rather than listing the column by number?
Thanks in advance.
Thanks in advance.
VBA Code:
Private Sub CommandButton1_Click()
'Copy input values to sheet
Dim lRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
With ws
.Cells(lRow, 1).Value = Me.VRM.Value
.Cells(lRow, 2).Value = Me.MOTExp.Value
.Cells(lRow, 3).Value = Me.Car.Value
.Cells(lRow, 4).Value = Me.Make.Value
.Cells(lRow, 5).Value = Me.Complete.Value
End With
'Clear input controls
Me.VRM.Value = ""
Me.MOTExp.Value = ""
Me.Car.Value = ""
Me.Make.Value = ""
Me.Complete.Value = ""
End Sub