Solved

Copy worksheets to new workbook without formulas referencing the old workbook

Posted on 2016-10-04
8
89 Views
Last Modified: 2016-10-13
I can't believe I'm not seeing the immediate solution to this, but I'm obviously not.

I'm copying two sheets to a new workbook.  When I do this the formulas are referencing the original workbook.  I do not want this.  The formulas only reference things that are copied over already (other cells on same tab or other tab that is being copied simultaneously).

How do I either copy without the file references while keeping my cell references or how do I rid myself of the file portion of the formulas while keeping the rest?  Adding code to my current macro is an acceptable solution.

PS - find and replace is a fail because it want't to point to another workbook.  I want to lose all file references, not change them.

For example:  
This in original file                                   =SUM(Annual!C10:C25)
in the new workbook becomes            =SUM([Budget.xls]Annual!C10:C25)                        
I want it back to the original                 =SUM(Annual!C10:C25)
0
Comment
Question by:Ray
8 Comments
 
LVL 30

Assisted Solution

by:Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj) earned 180 total points
ID: 41828695
You may try something like this......

Sub ReplaceFormula()
Dim cell As Range
On Error Resume Next
For Each cell In ActiveSheet.Cells.SpecialCells(xlCellTypeFormulas, 23)
   If InStr(cell.Formula, "[") > 0 Then
      cell.Formula = WorksheetFunction.Replace(cell.Formula, InStr(cell.Formula, "["), InStr(cell.Formula, "]") - InStr(cell.Formula, "[") + 1, "")
   End If
Next cell
End Sub

Open in new window

0
 
LVL 33

Expert Comment

by:Norie
ID: 41828696
What happens when you save the new workbook and close the original one?
0
 
LVL 27

Assisted Solution

by:Glenn Ray
Glenn Ray earned 160 total points
ID: 41828808
I'm not sure why a search and replace won't work using this method:
1) Immediately after copying the sheet(s) to the new workbook (both workbooks open), execute a replace (shortcut [Ctrl]+[H])
EE-replacefilenames.png
This will only remove the filenames on the displayed sheet.

-Glenn
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Author Comment

by:Ray
ID: 41828872
Guys, I feel like a total noob. I was the problem.  I thought I was copying all sheets I needed, but was not copying out a hidden worksheet.  Thus it was making file references since that sheet didn't exist in the new workbook.

Thanks for the effort!!!!
0
 
LVL 33

Assisted Solution

by:Rob Henson
Rob Henson earned 160 total points
ID: 41840134
You could have also used the Edit Links window if it occurs again.

On Data ribbon choose Edit Links, in the list that shows up choose the original file (Budget.xls) and click on change source. Browse to the file that you are working in and click OK, thus changing the source to itself.

Thanks
Rob H
0
 
LVL 10

Author Comment

by:Ray
ID: 41842339
What's the best method for closing this one?  
    Split amongst all or?
0
 
LVL 30

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 180 total points
ID: 41842345
If you resolved the question yourself, you may request to delete the question.
But if answers provided helped you to resolve your issue, you may consider accepting those solutions and split the points.
0
 
LVL 10

Author Closing Comment

by:Ray
ID: 41842376
Solved myself, but the answers did make me think about it more.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question