Merge two tables through macro

Ayushi Bansal 21 Reputation points
2022-07-01T21:37:15.797+00:00

I am trying to append two distinct tables with common column names into another table. Below is the code I am using

Sub Button1_Click()

Application.ScreenUpdating = False
Dim copySheet As Worksheet
Dim pasteSheet As Worksheet
Dim LastRow As Long

Set pasteSheet = Worksheets("Sheet3")

'first copy
Set copySheet = Worksheets("Sheet1")
copySheet.Range("table1").Copy Destination:=pasteSheet.Range("table3").End(xlUp).Offset(1)

'move to the next empty row
'LastRow = pasteSheet.Range("table3").End(xlUp).Row

'second copy
Set copySheet = Worksheets("Sheet2")
copySheet.Range("table2").Copy Destination:=pasteSheet(3).Range("table3").End(xlUp).Offset(1)

Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub

However, I am getting the error 'Object does not support this property or method' and only contents from table 1 are getting pasted.

0 comments No comments
{count} votes

Accepted answer
  1. Viorel 119.9K Reputation points
    2022-07-02T05:19:35.343+00:00

    Try removing "(3)".


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.