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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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,223,885
Messages
6,175,186
Members
452,615
Latest member
bogeys2birdies

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