VBA code to copy data from table to another table

hamohd70

New Member
Joined
Sep 21, 2016
Messages
25
Hello,

Please tell me where I went wrong..

I have 3 sheets. I'm trying to copy the content of table1 in sheet1 to table 3 in sheet3 and then copy content from table2 sheet2 to the end of table3 in sheet3...

Code:
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")

'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")

Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Sektor

Well-known Member
Joined
May 6, 2011
Messages
2,834
Code:
Sub Button1_Click()


Application.ScreenUpdating = False
Dim copySheet As Worksheet
Dim pasteSheet As Worksheet
Dim LastRow As Long
[COLOR=#ff0000][B]Dim sh3Col As Integer[/B][/COLOR]


Set pasteSheet = Worksheets("Sheet3")


'first copy
Set copySheet = Worksheets("Sheet1")
copySheet.Range("table1").Copy Destination:=pasteSheet.Range("table3")[B][COLOR=#ff0000].Cells(1)[/COLOR][/B]


'move to the next empty row
[COLOR=#ff0000][B]With pasteSheet
    sh3Col = .[/B][/COLOR][B][COLOR=#FF0000]Range("table3").Cells(1).Column[/COLOR][/B]
[B][COLOR=#ff0000]    LastRow = .Cells(.Rows.Count, [/COLOR][/B][B]sh3Col[/B][B][COLOR=#ff0000]).End(xlUp).Row
End With[/COLOR][/B]


'second copy
Set copySheet = Worksheets("Sheet2")
copySheet.Range("table2").Copy Destination:=[B][COLOR=#ff0000]pasteSheet(3).Cells(LastRow + 1, [/COLOR][/B][B]sh3Col[/B][B][COLOR=#ff0000])[/COLOR][/B]


Application.CutCopyMode = False
Application.ScreenUpdating = True


End Sub
 

Sektor

Well-known Member
Joined
May 6, 2011
Messages
2,834
hi.gif
 

joaofigu78

New Member
Joined
May 29, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Code:
Sub Button1_Click()


Application.ScreenUpdating = False
Dim copySheet As Worksheet
Dim pasteSheet As Worksheet
Dim LastRow As Long
[COLOR=#ff0000][B]Dim sh3Col As Integer[/B][/COLOR]


Set pasteSheet = Worksheets("Sheet3")


'first copy
Set copySheet = Worksheets("Sheet1")
copySheet.Range("table1").Copy Destination:=pasteSheet.Range("table3")[B][COLOR=#ff0000].Cells(1)[/COLOR][/B]


'move to the next empty row
[COLOR=#ff0000][B]With pasteSheet
    sh3Col = .[/B][/COLOR][B][COLOR=#FF0000]Range("table3").Cells(1).Column
    LastRow = .Cells(.Rows.Count, [/COLOR]sh3Col[COLOR=#ff0000]).End(xlUp).Row
End With[/COLOR][/B]


'second copy
Set copySheet = Worksheets("Sheet2")
copySheet.Range("table2").Copy Destination:=[B][COLOR=#ff0000]pasteSheet(3).Cells(LastRow + 1, [/COLOR]sh3Col[COLOR=#ff0000])[/COLOR][/B]


Application.CutCopyMode = False
Application.ScreenUpdating = True


End Sub
Hi,

Can You help me, my case is more simple, just copy all the table to the end of another table and remove duplicates of table.


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

'sheets Copy and paste
Set pasteSheet = Worksheets("PASTETT")
Set copySheet = Worksheets("TTLINK")

'lastrow
LastRow = pasteSheet.Range("table3").End(xldown).Row + 1

copySheet.Range("TT_BlackFriday__2").Copy Destination:=pasteSheet.Range("table3").Cells(LastRow + 1)


Application.CutCopyMode = False
Application.ScreenUpdating = True
 

Watch MrExcel Video

Forum statistics

Threads
1,123,158
Messages
5,600,054
Members
414,357
Latest member
Gemma_R

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top