Copy from one table to another

henrik2h

Board Regular
Joined
Aug 25, 2008
Messages
155
Office Version
  1. 2021
Platform
  1. Windows
Anyone knows why (Copy - Destination) does not work but Pastespecial does? What is the most efficient way to copy from one table in workbook 1 to another table in workbook 2?

Code:
Sub Import_data()

    Dim wb As Workbook, wb2 As Workbook
    Dim ws As Worksheet
    Dim vFile As Variant


    Application.ScreenUpdating = False
    
    'Set target workbook
    Set wb = ActiveWorkbook
    'Open the source workbook
    vFile = Application.GetOpenFilename("Excel-files,*.xlsx", _
        1, "Select Source File To Open", , False)
    'if the user didn't select a file, exit sub
    If TypeName(vFile) = "Boolean" Then Exit Sub
    Workbooks.Open vFile
    'Set source workbook
    Set wb2 = ActiveWorkbook


    'Copy data from a table in the source workbook to another table in the target workbook
    On Error Resume Next
        
    wb.Sheets("sheet1").Range("tbTARGET[Number]").Copy Destination:=wb2.Sheets("sheet1").Range("tbSOURCE[Number]").Range
    
    wb.Sheets("sheet1").Range("tbTARGET[Date]").Copy Destination:=wb2.Sheets("sheet1").Range("tbSOURCE[Date]").Range
    
    
    
    wb2.Sheets("sheet1").Range("tbSOURCE[Name]").Copy
    wb.Sheets("Sheet1").Range("tbTARGET[Name]").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
    Application.CutCopyMode = False
    wb2.Close savechanges:=False
        
    Application.ScreenUpdating = True


    
    
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,223,888
Messages
6,175,213
Members
452,618
Latest member
Tam84

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