This is the code that should work for me-
Option Explicit
Dim newrow As ListRow
Dim ws2 As Worksheet
Dim tbl1 As ListObject
Private Sub CommandButton1_Click()
Set ws2 = Sheet2
Set tbl1 = ws2.ListObjects("Table1")
Set newrow = tbl1.ListRows.Add
With newrow
.Range(1) = tbl1.ListRows.Count
.Range(2) = Date
.Range(3) = Sheet1.Cells(2, 3)
.Range(4) = Sheet1.Cells(3, 3)
.Range(5) = Sheet1.Cells(12, 9)
End With
End Sub
My table name is Table1. It table has 5 columns.
Sheet 1 name is Sheet1
& Sheet2 Name of Sheet2 (on this sheet I inserted the table with appropriate column headings)
So I added a command button and then pasted this code.
Now I am getting a range out of script error.
getting an error in this line of code - Set tbl1 = ws2.ListObjects("Table1")
What am I doing wrong? checked the name of the table. Its Table1
Bookmarks