Solved

Copy worksheets to new workbook without formulas referencing the old workbook

Posted on 2016-10-04
8
74 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 28

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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 32

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 28

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now