VBA code to copy data from table to another table

hamohd70

New Member
Joined
Sep 21, 2016
Messages
35
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
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Rich (BB code):
Sub Button1_Click()


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


Set pasteSheet = Worksheets("Sheet3")


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


'move to the next empty row
With pasteSheet
    sh3Col = .Range("table3").Cells(1).Column
    LastRow = .Cells(.Rows.Count, sh3Col).End(xlUp).Row
End With


'second copy
Set copySheet = Worksheets("Sheet2")
copySheet.Range("table2").Copy Destination:=pasteSheet(3).Cells(LastRow + 1, sh3Col)


Application.CutCopyMode = False
Application.ScreenUpdating = True


End Sub
 
Last edited by a moderator:
Upvote 0
hi.gif
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,391
Messages
6,119,239
Members
448,879
Latest member
VanGirl

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
Back
Top