Linked cells when transferring worksheets between workbooks

TheRedCardinal

Active Member
Joined
Jul 11, 2019
Messages
250
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
My macro opens a template file, and copies two sheets from that template into the workbook running the macro.

The sheets have linked cells, very simple "=" links.

But I have discovered that when I move the sheets over, the links remain anchored to the original template workbook, instead of being linked to the sheet in the new workbook.

Is there a way around this when copying the worksheets over?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
We need more information.
Are the sheets being moved just linked to each other ?
If so then you need to copy them all at once.
Do any of the sheets have tables in them ? This will prevent you from copying them all at once.
 
Upvote 0
Hi,

Thanks for your help.

Here is the code that copies the sheets:

VBA Code:
Set WS4 = Wbk2.Sheets(WS1.Range("B5").Value)
WS4.Name = "Process"
WS4.Copy After:=WS1
Set Ws3 = Wbk.Sheets("Process")
Wbk2.Sheets("Settings").Copy After:=Wbk.Sheets(Wbk.Worksheets.Count)
Wbk2.Sheets("Input Summary").Copy After:=Wbk.Sheets("Invoice Checks")
Wbk2.Sheets("Output Summary").Copy After:=Wbk.Sheets("Input Summary")
Wbk2.Sheets("Return").Copy Before:=WS2

Wbk2.Close SaveChanges:=False

The links are between cells in "Return", and the "Input Summary" and "Output Summary" sheets.

There are no tables in place on any of the sheets.
 
Upvote 0
You don't have a definition for Wbk or Wbk2 or WS1 or WS2, so I am unsure of what the destination is:
See if the below gives you an idea of how to proceed. You need to copy all the sheets at once so the links are to the same workbook.

In arrSht put your own sheet names.
You will then need to use Move to rearrange the sheets in the order you want them in.

Rich (BB code):
Sub TestCopy()
    Dim wbNew As Workbook, wbCurrent As Workbook
    Dim arrSht As Variant
    
    Set wbCurrent = ActiveWorkbook
    Set wbNew = Workbooks.Add

    arrSht = Array("SheetA", "Sheet 2", "Sheet3")
    
    wbCurrent.Worksheets(arrSht).Copy after:=wbNew.Sheets(1)
    
End Sub
 
Upvote 0
Thanks,

I get a Type Mismatch error in the copy line here:

VBA Code:
Set Wbk2 = Workbooks.Open(Templatefile)

'Copy Sheets, and populate cells

CopySheets = Array(Wbk2.Sheets(WS1.Range("B5").Value), Wbk2.Sheets("Settings"), Wbk2.Sheets("Input Summary"), Wbk2.Sheets("Output Summary"), Wbk2.Sheets("Return"))

Wbk2.Worksheets(CopySheets).Copy after:=Wbk.Sheets("Launch")

The 5 sheets are all correct and in the array.

Wbk is my calling workbook where the macro is stored, and has a sheet called "Launch".
 
Upvote 0

Forum statistics

Threads
1,223,882
Messages
6,175,164
Members
452,615
Latest member
bogeys2birdies

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