I want to ask how to add data into into a particular row in an Excel spreadsheet using a Userform
.
When I add a new product A to the sheet, I want the new data to be located under the last row of product A, and the same for other products B and C.
Is there any way to sort the data exactly when I enter the new data into the existing table?
The code I have below adds data row by row, no matter what product I enter, making the table unsorted and appearing scattered.
Private Sub CommandButton1_Click()
Dim LastRow As Object
Set LastRow = Sheet1.Range("a65536").End(xlUp)
LastRow.Offset(1, 0).Value = TextBox1.Text
LastRow.Offset(1, 1).Value = TextBox2.Text
LastRow.Offset(1, 2).Value = TextBox3.Text
MsgBox "One record written to Sheet1"
If MsgBox("Do you want to continue entering data?", vbYesNo + vbCritical, "Caution") = vbYes Then
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
Else
End
TextBox1.SetFocus
Unload Me
End If
End Sub