Find/Replace Named Cells

ccs0148

New Member
Joined
Mar 23, 2011
Messages
2
I am working with a workbook that has alot of named cells. The named cells are hindering the functionality of another workbook that is linking to it. I want to write a macro that will automatically find and replace all of the named cells in the formulas with the actual cell location. I.E. I am looking to change a formula from =(Invst_Amt*.12) to =(C12*.12) where Invst_Amount is located at C12. I have simplifed the math to make it easier to see. There are about 100 named ranges in the workbook so I am trying to keep from using the Replace function and manually keying in all of the names.

I would appreciate anyones help.
 

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.
There is a free Excel add-in called Name Manager. It has a feature to replace a Name in all the formulas that use it with its Refers To reference. It also has several other useful features if you use a lot of Names.
 
Upvote 0
I found this online. It works.

Option Explicit

Public Sub ReplaceNamesWithRefs()
Dim rng As Excel.Range
Dim wks As Excel.Worksheet
Dim nme As Name
Dim nCt As Integer
Dim szWkbName As String
Dim szSwitchString As String

nCt = 1

With Application
.EnableEvents = False

On Error Resume Next
'Loop through all names in the workbook
For Each nme In ThisWorkbook.Names

'Store each name object in a variable
szWkbName = ThisWorkbook.Names(nCt).Name
.StatusBar = "Checking Defined Name " & CStr(szWkbName)

'Store each names RefersTo value in a variable that trims the (=)&($)
szSwitchString = Replace$(ThisWorkbook.Names(nCt).RefersTo, "=", "")
szSwitchString = Replace$(szSwitchString, "$", "")

'===================================================================
'Loop through the sheets collection, replacing the names with
'the actual range references
For Each wks In ThisWorkbook.Worksheets

With wks.Cells.SpecialCells(xlCellTypeFormulas)
.Replace$ szWkbName, szSwitchString, xlPart, , True
.Replace$ wks.Name & "!", "", xlPart, , True
End With

Next wks
'===================================================================

nCt = nCt + 1

Next nme

'This code portion was created by Jim Rech
For Each wks In ThisWorkbook.Worksheets
With wks
.TransitionFormEntry = True
For Each rng In .Cells.SpecialCells(xlFormulas)
rng.Formula = rng.Formula
Next rng
.TransitionFormEntry = False
End With
Next wks

.EnableEvents = True
.StatusBar = False
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,713
Members
452,939
Latest member
WCrawford

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