Hello Soulbringer,
Sorry for the delay. The attached workbook has been modified from your original post. A dynamic named range "Project_Number" now refers to the project numbers from A2 down to the last project number in column "A". A button has been added to the "Data" sheet to run the macro.
' Thread: http://www.excelforum.com/excel-programming/839394-find-and-replace-text-within-string.html
' Poster: Soulbringer
' Written: June 19, 2012
' Author: Leith Ross (www.excelforum.com)
Sub UpdateProjectLinks()
Dim C As Long
Dim Formula As Variant
Dim Formulas As Variant
Dim Project As Range
Dim R As Long
Dim RegExp As Object
Dim Wks As Worksheet
Application.DisplayAlerts = False
Set RegExp = CreateObject("VBScript.RegExp")
RegExp.IgnoreCase = True
RegExp.Pattern = "\[(\w+\.xlsx)\]"
For Each Project In Range("Project_Number")
On Error Resume Next
Set Wks = Worksheets(Project.Text)
On Error GoTo 0
If Err = 9 Or Wks Is Nothing Then GoTo SkipUpdate
Formulas = Wks.UsedRange.Formula
For C = 1 To UBound(Formulas, 2)
For R = 1 To UBound(Formulas, 1)
Formula = Formulas(R, C)
If Left(Formula, 1) = "=" Then
If RegExp.Test(Formula) = True Then
Formulas(R, C) = RegExp.Replace(Formula, "[" & Project.Text & ".xlsx]")
End If
End If
Next R
Next C
Wks.UsedRange.Formula = Formulas
SkipUpdate:
Set Wks = Nothing
Next Project
Application.DisplayAlerts = True
End Sub
Bookmarks