Right let's try to sort out the rest of your thread next, and then we can pull it all together.
I have tried to work out what we need to strip out from the cells in sheet "Destination" to leave you with the bare formula.
The external link is always wrapped in single quotes ' '
- the macro splits each cell every time it encounters character '
- dumps that bit of string into an array
- removes the string if it contains a " \ " (which is present in all links)
- joins all the pieces back together again
- removes any !
- writes resultant string to 2 new worksheets
- FormulaSheet should contain what you are looking for
- TextSheet allows you to see the formula without going into individual cells
So test as follows
- create a test copy of your file (just in case!!)
- copy the VBA below into Module1
- run it and check to see if it is what you are looking for
Sub ClearLinks()
If Evaluate("ISREF('FormulaSheet'!A1)") Then Sheets("FormulaSheet").Cells.ClearContents Else Sheets.Add.Name = "FormulaSheet"
If Evaluate("ISREF('TextSheet'!A1)") Then Sheets("TextSheet").Cells.ClearContents Else Sheets.Add.Name = "TextSheet"
Dim wsT As Worksheet, wsF As Worksheet, wsD As Worksheet
Set wsT = Sheets("TextSheet")
Set wsF = Sheets("FormulaSheet")
Set wsD = Sheets("DestinationSheet")
Dim text As String, strFormula As String
Dim formArr As Variant
Dim a As Long, i As Long
For Each cell In wsD.UsedRange.Cells
'split the text for this cell
text = cell.Formula
formArr = Split(text, "'")
'create new formula string
For a = 0 To UBound(formArr)
If InStr(CStr(formArr(a)), "\") > 0 Then
formArr(a) = ""
Else
End If
strFormula = strFormula & CStr(formArr(a))
Next a
'put in equivalent cell on new sheet
strFormula = Replace(strFormula, "!", "")
cellAddress = cell.Address(0, 0)
wsT.Range(cell.Address(0, 0)) = "F: " & strFormula
wsF.Range(cell.Address(0, 0)) = Replace(wsT.Range(cell.Address(0, 0)), "F: ", "")
strFormula = ""
Next
End Sub
Bookmarks