Adding data to a worksheet from a UserForm

K

Kezza

Hello all, I am trying to get my head around adding data to a worksheet
via a userform. I want to add to lists in sheet 3 in the next available
row but I keep getting a application-defined or object defined error.
Debug points me to the 2nd line of the macro. (Set LastRow).
Can any one help? Thanks
Kezza

Private Sub CommandButton6_Click()
Dim LastRow As Object

Set LastRow = Sheet3.Range("a65536").End(x1Up)

LastRow.Offset(1, 0).Value = TextBox6.Text
LastRow.Offset(1, 1).Value = TextBox7.Text
LastRow.Offset(1, 2).Value = TextBox8.Text

MsgBox "One record written to Sheet3"
response = MsgBox("Do you want to enter another record?", vbYesNo)

If response = vbYes Then
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""

TextBox6.SetFocus

Else
Unload Me
End If
End Sub
 
M

Muhammed Rafeek M

pls modify your code like this:

Dim LastRow As Range

Set LastRow = Sheet3.Range("a65536").End(xlUp)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top