VBA code to find/replace #ref in formula

WWII_Buff

Board Regular
Joined
Nov 13, 2017
Messages
88
I have searched high and low. Is there a way to find several #REF ! in a formula string within a range (B11:AP55) in a single worksheet and replace it with a "Master".

Code:
=SUMIFS(INDEX([URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=REF]#REF[/URL] !,0,MATCH('SITE'!AP$3,[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=REF]#REF[/URL] !,0)),[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=REF]#REF[/URL] !,'SITE'!$A11,[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=REF]#REF[/URL] !,'SITE'!$A$45)
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Code:
Sub test()
With Range("B11:AP55").SpecialCells(xlCellTypeFormulas)
    .Formula = Replace(.Formula, "#REF", "Master", , , vbTextCompare)
End With

End Sub
 
Upvote 0
Beginning with Excel 2013 and Since - there is a NEW function/formula = FORMULATEXT(A1) that might be helpful to you.
 
Upvote 0
Thank you for your help Jim - I was thinking along the lines of Neil - but this vba is erroring out.

To give you more context, I blowing away the master sheet and would like to link back to it when it is recreated.
 
Last edited:
Upvote 0
Thank you for your help Jim - I was thinking along the lines of Neil - but this vba is erroring out.

To give you more context, I blowing away the master sheet and would like to link back to it when it is recreated.

I think you can wrap the INDIRECT() around your "Master" sheet name, and doing so will not cause it to be replaced with #REF when it is "blown-away".
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

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