Cell references in formulas with precedent data

carl.hayes

New Member
Joined
Oct 16, 2008
Messages
21
All,
I am looking for a formula or macro to do the following

Copy the contents of a cell and then replace any reference to that cell in the rest of the spreadsheet with the contents of the cell.
E.g. cell f3 = a3*25
I want to then in all other cells which reference cell f3 in a formula replace f3 with a3*25

Can anyone help?? Please note that this will be needed for quite a large badly formatted spreadsheet with a large number of formulas contained within it.
 
Last edited:

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Something like this...

Code:
Sub Replace_formula()
Dim a As String
Dim r As Range
Dim s As String



a = ActiveCell.Address
s = Replace(ActiveCell.Formula, "=", "")

For Each r In ActiveSheet.UsedRange
If r.HasFormula = True Then
    If InStr(1, r.Formula, a, 1) > 0 Then
        r.Formula = Replace(r.Formula, a, s)

    End If
End If
Next r

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,259
Members
452,901
Latest member
LisaGo

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