What I Have: I have two workbooks, one with some data I need, and one which acts as a general template. When the code I run the template saves as a copy and should then fetch some data from the data workbook.
I want to copy the data of a table from the data workbook into a similarly structured, but with extra columns, table in the template workbook. It is worth noting that the table in the template workbook, is empty and only has 1 row
Currently, the code looks something like this.
Initial
Set chWb = Excel.Workbooks.Open(LinkToDataSource)
Set sht = chWb.Worksheets(SheetWithTable)
Set tbl = sht.ListObjects(TableWeWantToCopyFrom)
' Same set for the one we want to copy to
Set checkTbl = SheetName.ListObjects(TableWeWantToPasteInto)
Then the methods i have tried
'Selecting and copy the data
tbl.DataBodyRange.Select.Copy
'Paste
checkTbl.DataBodyRange.PasteSpecial xlPasteValues
This Copies, from what I can see, correctly from the datasheet. However, it throws an error 91 "Object variable or with block not set" on the line that in theory should paste it.
Maybe adding the row space first? Tried to add space first using the ListRow.Count of the data table
checkTbl.RowList.Add(tbl.ListRows.Count)
But this line in itself throws a Subscript out of range error
Any ideas and knowledge are welcome.