I'm trying to look through formulas in a range of cells and match up named ranges in the worksheet to any named ranges in the formula and replace the named ranges with their reference cells.
Dim rng As Range
Dim workrng As Range
Dim xname As Name
Dim arr() As Variant
Dim arr_string as String
Set workrng = Application.Selection
Set workrng = Application.InputBox("txt", "header txt", workrng.Address, Type:=8
Set workrng = workrng.SpecialCells(xlCellTypeFormulas)
For Each rng In workrng
For Each xname in ThisWorkbook.names
arr = Split(xname.Name, "!")
arr_string = arr(1)
Debug.Print arr_string
If InStr(rng.Formula, xname.Name) > 0 Then
rng.Formula = VBA.Replace(rng.Formula, xname.Name, VBA.Replace(xname.RefersTo, "=", ""))
End If
Next
Next
When I debug print "xname.Name" I get results that include the sheet name. For example: Specifications!_MyNamedRange. However, the formula in the cell only says: _MyNamedRange. That's why I'm trying to split it. However, when I debug my array, there is nothing in it.
.RefersTo
property. – Ron Rosenfeld$A$1:$B$2
) out of the named range confuses me regarding what you actually want to accomplish – Marcucciboy2