Remove path from copied formulas

rex759

Well-known Member
Joined
Nov 8, 2004
Messages
610
Office Version
  1. 365
Platform
  1. Windows
Hello,
I’m using the code,
Code:
Workbooks(mydatafile).Sheets("team calendar").Copy _
       after:=Workbooks(TEMPFILE).Sheets("Sheet1")

to copy a worksheet to a new workbook. What is happening is the path to the Master workbook is adding itself to each of the formulas.
Example;

=IF(ISERROR(INDEX('C:\Users\Michael''s\Desktop\[Master.xls]Data'!$U$2:$U$2000,MATCH(--'Team Calendar'!A6,'C:\Users\Michael''s\Desktop\[Master.xls]Data'!$F$2:$F$2000,0),0)),"",INDEX('C:\Users\Michael''s\Desktop\[Master.xls]Data'!$U$2:$U$2000,MATCH(--'Team Calendar'!A6,'C:\Users\Michael''s\Desktop\[Master.xls]Data'!$F$2:$F$2000,0),0))

I thought I could run a code to remove the path at the end but didn't have any luck. I was using.

Code:
    Dim cell As Range, n As Variant

    For Each cell In Workbooks("tempfile").Sheets("team calendar").Cells.SpecialCells(xlFormulas)
        n = Application.Find("]", cell.Formula)
        If Not IsError(n) Then
            cell.Formula = "='" & Right(cell.Formula, Len(cell.Formula) - n)
        End If
    Next cell

I get an application error on this line.

Code:
cell.Formula = "='" & Right(cell.Formula, Len(cell.Formula) - n)

any help is appreciated.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Untested, but you can try this:
Code:
Sub trial()
Const path = "'C:\Users\Michael''s\Desktop\[Master.xls]"
Dim rng As Range
Set rng = Workbooks("tempfile").Sheets("team calendar").Cells.SpecialCells(xlFormulas)
With rng
    .Replace path, ""
End With
    
End Sub
 
Upvote 0
You can also go to Edit | Links. Then select the external workbook, and change the link. Select the workbook that you are in (i.e., you want to "link it to itelf")

In 2007 edit links is on the data tab.

If you insert a new sheet first, then copy the cells and paste them in the new sheet, I think it might not create the link (as opposed to copy the entire sheet itself into a new workbook)
 
Upvote 0
Thank you both for your replies. I realized after trial an error that I had to change most of the cell references in the formulas that carried over to the new worksheet. This made it too cumbersome to just update the link. I have a few ideas to try. If I get suck again, I’ll post.

Thank you
 
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,595
Members
452,927
Latest member
whitfieldcraig

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