Copy and Paste a table - why can't I do this without breaking all the best practice rules?

TheRedCardinal

Board Regular
Joined
Jul 11, 2019
Messages
243
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi all,
I am trying to move a table from one worksheet to a predefined worksheet in another, loaded worksheet.

However I can't get it to work without breaking all the speed rules around selecting, activating, pasting etc.

I have added the relevant code here:

VBA Code:
    Dim Parent As String, Filename As String, Path As String
    Path = Application.ActiveWorkbook.Path & "\..\"

    Set WBk1 = ThisWorkbook
    
    Application.DisplayAlerts = False
    Application.AskToUpdateLinks = False
    
    Set WBk2 = Workbooks.Open("Link to source file")
    
    Set WS1 = WBk1.Sheets("2. Final Data")
    Set WS2 = WBk2.Sheets("2. Imported Data")
    
    WS2.Cells.Clear
    WS2.Range("A1").Select
    
    WBk1.Activate
    WS1.Activate
    WS1.Range("Final_Table[#All]").Select
    Selection.Copy
    WBk2.Activate
    WS2.Activate
    WS2.Paste
    
    ActiveWorkbook.SaveAs Filename:=Path & "\" & Filename
    ActiveWorkbook.Close
    Application.DisplayAlerts = True
    
    WBk1.Activate
    
End If

I had to expand all these lines - for example, when I tried to use something like this:

VBA Code:
WS1.Range("Final_Table[#All]").Copy
WS2.Range("A1").Paste

I get the run time error telling me the object doesn't support this property or method.

I've literally had to go through and select pasting cells, activate them, switch workbooks etc to make this work which seems unwieldy to me.

Any tips?

Thanks!
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
VBA Code:
WS1.Range("Final_Table[#All]").Copy
WS2.Range("A1").Paste
I get the run time error telling me the object doesn't support this property or method.
Try changing Paste to PasteSpecial or
VBA Code:
WS1.Range("Final_Table[#All]").Copy WS2.Range("A1")
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,267
Members
449,075
Latest member
staticfluids

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