I can't understand why the following erroring? when I am trying to enter data from userform to excel.
Sub Button()
Dim i As Integer
Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet
Dim LastRow As Long
Dim wsName As String
wsName = FormSelectSht.ComboBoxMachines.Value
For Each ws In wb.Sheets
If ws.Name = wsName Then ws.Activate
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
Next
'énter data into active sheet
'ws.Range("A" & LastRow) = Date
With ws
.Range("B" & LastRow).Value = FormSelectSht.ComboBoxProduct.Value
' .Cells(LastRow, 2).Value = FormSelectSht.ComboBoxProduct.Value
'.Cells("B" & LastRow).Value = FormSelectSht.ComboBoxProduct.Value
'ws.Range("C" & LastRow) = juliandt
'ws.Range("D" & LastRow).Value = FormSelectSht.TextBoxOperator1.Value
'ws.Range("E" & LastRow).Value = FormSelectSht.TextBoxOperator2.Value
'ws.Range("F" & LastRow).Value = FormSelectSht.TextBoxLot.Value
End With
End Sub
Sub Button()
Dim i As Integer
Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet
Dim LastRow As Long
Dim wsName As String
wsName = FormSelectSht.ComboBoxMachines.Value
For Each ws In wb.Sheets
If ws.Name = wsName Then ws.Activate
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
Next
'énter data into active sheet
'ws.Range("A" & LastRow) = Date
With ws
.Range("B" & LastRow).Value = FormSelectSht.ComboBoxProduct.Value
' .Cells(LastRow, 2).Value = FormSelectSht.ComboBoxProduct.Value
'.Cells("B" & LastRow).Value = FormSelectSht.ComboBoxProduct.Value
'ws.Range("C" & LastRow) = juliandt
'ws.Range("D" & LastRow).Value = FormSelectSht.TextBoxOperator1.Value
'ws.Range("E" & LastRow).Value = FormSelectSht.TextBoxOperator2.Value
'ws.Range("F" & LastRow).Value = FormSelectSht.TextBoxLot.Value
End With
End Sub