VBA Request - Break External Links Leave Formulas and Values

aalcorn

New Member
Joined
Aug 24, 2015
Messages
2
Hi, I am trying to modify this VBA I found on the forum that is several years old.

Sub Test()
Const LinkName As String = "Book1.xlsx"
Dim CalcMode
Dim ws As Worksheet
Dim WorkRange As Range
Dim Cell As Range
Dim FormulaParts As Variant
Dim i As Integer
Dim NewFormula As String
CalcMode = Application.Calculation
Application.Calculation = xlCalculationManual
On Error Resume Next
Set ws = ActiveSheet
Set WorkRange = ws.Cells.SpecialCells(xlCellTypeFormulas)
If Err <> 0 Then Exit Sub
For Each Cell In WorkRange
With Cell
If InStr(1, .Formula, "[" & LinkName, 1) Then
FormulaParts = Split(Replace(.Formula, "=", ""), "+")
For i = LBound(FormulaParts) To UBound(FormulaParts)
If InStr(1, FormulaParts(i), "[" & LinkName, 1) Then
FormulaParts(i) = 0
End If
Next i
NewFormula = Join(FormulaParts, "+")
NewFormula = Replace(NewFormula, "0+", "")
NewFormula = Replace(NewFormula, "+0", "")
If Len(NewFormula) > 1 Then
.Formula = "=" & NewFormula
Else
.ClearContents
End If
End If
End With
Next Cell
Application.Calculation = CalcMode
End Sub


I need to create the same effect of editing a formula [f2] and calculating the value [f9] of a specific sheet reference while keeping the rest of the formula intact. I moved the sheet to an external file to match the VBA I found.

I am new to VBA but can see there should be a way to modify this to calculate the value instead of just removing the reference. Editing each individual formula would take a very long time so I am looking for a worksheet solution.

Thanks
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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