Changing multiple cell references to absolute references within formula

JWill78

New Member
Joined
Feb 13, 2015
Messages
10
Hi

I have a row of cells each with formula along the lines of: =A1xB1xInputs!A1xInputs!B1

What I'd like to do is convert all of the references to the Inputs sheet in each cell to absolute references, but leave the others as relative references. I have VBA that will convert all references to absolute/relative but other than doing a separate find and replace for each individual reference to the Input sheet I can't figure out how to quickly change just those references for all selected cells.

All help greatly appreciated!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Have found a solution elsewhere, posted below in case be of use to others:

Sub ConvertInputsToAbsoluteReferences()
Dim cell As Range
Dim formula As String
Dim regex As Object
Dim matches As Object
Dim match As Object
Dim newFormula As String

' Create a new regular expression object
Set regex = CreateObject("VBScript.RegExp")

' Pattern to match references like Inputs!A1, Inputs!Z99, etc.
regex.Pattern = "Inputs!\$?[A-Z]+\$?[0-9]+"
regex.Global = True

' Loop through all selected cells
For Each cell In Selection
If cell.HasFormula Then
formula = cell.Formula

' Find all matches of Inputs! references in the formula
Set matches = regex.Execute(formula)

' Start with the original formula
newFormula = formula

' Loop through each match found
For Each match In matches
' Convert each matched reference to an absolute reference
newFormula = Replace(newFormula, match.Value, Application.ConvertFormula(match.Value, xlA1, xlA1, xlAbsolute))
Next match

' Update the formula in the cell
cell.Formula = newFormula
End If
Next cell
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,117
Members
453,021
Latest member
Justyna P

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