I'm making a userform for user to input an item with its quantity and price to the receipt because I want to lock the whole sheet so my employee cannot edit the receipt view. What I'm trying to do is when user already add the first item (row 16) and want to add another item, the item is added into the row below the first item (row 17). I already make the code but the problem is that it doesn't detect the last row of the data so it keeps overwriting the first row which is row 16 and doesn't goes down to row 17.
Can somebody help me with fixing the code?
Private Sub btnSubmit_Click()
Dim lastRow2 As Long, m As Variant, str As String
Dim rng1, cell1 As Range
If tbQty.Value > 0 Then
lastRow2 = ThisWorkbook.Sheets("sheet1").Range("A16" & Rows.Count).End(xlUp).Row+1
Sheets("sheet1").Range("A" & lastRow2).Value = tbProduk.Value
Sheets("sheet1").Range("C" & lastRow2).Value = Val(tbQty.Value)
Sheets("sheet1").Range("D" & lastRow2).Value = Val(tbPrice.Value)
End If
tbProduk.Value = ""
tbQty.Value = ""
tbPrice.Value = ""
tbProduk.SetFocus
End Sub