Table Reference in Formula Changes When Worksheets Copied

91 views Asked by At

I have two sheets in "Property" Workbook that I am copying to "UQP" Workbook.

PropertyCoverage - Houses formula =VLOOKUP("PF",tPremium,2,0) among other text and simple SUM formula.

xmlProperty - Houses table tPremium (among other tables; all tables mapped to XML Source)

When I copy these two sheets (simultaneously) into the UQP workbook the tPremium reference in the formula in the PropertyCoverage sheet automatically changes to tAutoForms, which is another table in the UQP workbook (that has nothing to do with the formula). UQP workbook has several other sheets and tables.

I don't know why this changes automatically, but I think it has something to do with the fact that Excel cannot copy multiples sheets when at least one sheet contains a table.

I have tried the solution below (referenced from here). However, the same issue happens. The issue does not happen if I copy to a new workbook. ... Bear with ActiveWorkbook, etc, I only used this as test to see if it would work

Sub Copy_Worksheets()

    Dim wbMaster As Workbook
    Set wbMaster = Workbooks("UniversalQuoteProposal.xlsb")
    Dim TheActiveWindow As Window
    Dim TempWindow As Window
    With ActiveWorkbook
        Set TheActiveWindow = ActiveWindow
        Set TempWindow = .NewWindow
        .Sheets(Array("PropertyCoverage", "xmlProperty")).Copy Before:=wbMaster.Worksheets(1)
    End With
    TempWindow.Close

End Sub

Here is my original copy code:

Sub CopySheetsToMaster()

Dim wbMaster As Workbook
Set wbMaster = Workbooks("UniversalQuoteProposal.xlsb")

Dim sSheetName As String
sSheetName = Replace(ThisWorkbook.Name, ".xlsb", "")

Dim sSheets As Variant
sSheets = Array(sSheetName & "Coverage", "xml" & sSheetName)

'*** => This is where tPremium gets automatically changed to tAutoForms
ThisWorkbook.Worksheets(sSheets).Copy Before:=wbMaster.Worksheets(1)

wbMaster.ChangeLink ThisWorkbook.FullName, wbMaster.FullName, xlLinkTypeExcelLinks

End Sub

Lastly, I can work around this by doing a Replace after the sheets are copied, but since this will scale out to a need to bring a possible 7-10 other workbooks with potential formula references to tables and such, I would rather find a cleaner solution if it exists.

Lastly, I am using Excel 2010.

0

There are 0 answers