I trying to write this macro with the intention of when the command button is selected specified cell data from the current sheet is copy and pasted to the next available row on another sheet. This syntax works fine on a user form but I'm having trouble trying to achieve the same thing with just a work sheet. When I try to run I get error 91. Below is what I've got so far:
Private Sub CommandButton1_Click()
Dim lg As Worksheet
Set lg = Sheets("Log")
lg.Select
lg.Range("A2:T2").Select
Selection.ListObject.ListRows.Add (1)
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
lg.Cells(2, 1) = Sheets("sheet2").Range("A1")
Unload Me
lg.Select
End Sub
Private Sub CommandButton1_Click()
Dim lg As Worksheet
Set lg = Sheets("Log")
lg.Select
lg.Range("A2:T2").Select
Selection.ListObject.ListRows.Add (1)
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
lg.Cells(2, 1) = Sheets("sheet2").Range("A1")
Unload Me
lg.Select
End Sub