Hi guys,
I am trying to write a code within a userform which can be used to enter data on 3 columns. The columns are F, G, H and the row start from row 4. But when I try to run the code I get an object error on ActiveSheet.Cells(lastrow + 1, 6).Value = TextBox1.Value. I'm new to VBA so the whole code could be wrong but I'm pretty sure there's a small fix I need. Please see an image of the userform and target range I have created as well. "TargetSheet" is a combo box I have created with items with names of sheets I want the data to be copied. CommandButton1 is the "Save Entry" button.
Thank you very much already!
I am trying to write a code within a userform which can be used to enter data on 3 columns. The columns are F, G, H and the row start from row 4. But when I try to run the code I get an object error on ActiveSheet.Cells(lastrow + 1, 6).Value = TextBox1.Value. I'm new to VBA so the whole code could be wrong but I'm pretty sure there's a small fix I need. Please see an image of the userform and target range I have created as well. "TargetSheet" is a combo box I have created with items with names of sheets I want the data to be copied. CommandButton1 is the "Save Entry" button.
Thank you very much already!
VBA Code:
Private Sub CommandButton1_Click()
Targetsheet = ComboBox1.Value
If Targetsheet = "" Then
Exit Sub
End If
Worksheets(Targetsheet).Activate
lastrow = ActiveSheet.Cells(Rows.Count, 4).End(xlUp).Row
ActiveSheet.Cells(lastrow + 1, 6).Value = TextBox1.Value
ActiveSheet.Cells(lastrow + 1, 7).Value = TextBox2.Value
ActiveSheet.Cells(lastrow + 1, 8).Value = TextBox3.Value
MsgBox ("Data entry is successful!")
End Sub