I wasn't attempting to belittle you, only to educate you on what we
volunteers need to work with in trying to answer your, as well as all the
other poster's, questions. You question in this thread was a little thin on
the detail you wanted and it looked like you were saying "go find my other
post to find out what I am looking for". By the way, I do apologize for
saying I couldn't find your other thread... I'm not sure what happened but,
when I first looked, I could find any other posts by you... I just looked
again and this time I see them.
Anyway... to your question. The macro I am posting below works, but only for
simple cell references. If you have any range references, those will remain
as is. Also, the macro will not work for references on other worksheets
(seems to be a limitation of the Precedents property). I **might** be able
to develop code to work around that, but I'm thinking it will be difficult
(unless all your worksheet references always had apostrophes around their
names... I'm thinking that might let me hone in on the worksheet's name
easier).
To use the following macro, select the cell or cells you want to perform
this operation on and then run the macro. One thing you will need to do
manually is set the location for the output as a row/column offset from the
selected cell or cells. To do this, just change the two Const statements to
set the row offset (0 means same row) and the column offset (0 means same
column). As set in my code, I post the formulas in the row underneath the
selected cell or cells (as per your stated desire to have C2's modified
formula posted in C3). Note that to tell which is the Row 1 header text,
that text is listed with angle brackets around it. For example, if the
header text is Year, it will be shown in the modified formula as <Year> so
that you can tell it from the rest of the text (function names, etc.) that
may be in the formula as well...
Sub ReferenceHeaderText()
Dim R As Range, V As Range
Dim CellFormula As String
Const RowOffset As Long = 0
Const ColumnOffset As Long = 1
For Each R In Selection
CellFormula = Replace(R.Formula, "$", "")
For Each V In R.Precedents
If InStr(CellFormula, V.Address(0, 0) & ":") = 0 And _
InStr(CellFormula, ":" & V.Address(0, 0)) = 0 Then
CellFormula = Replace(CellFormula, V.Address(0, 0), "<" & _
Cells(1, V.Column).Value & ">")
End If
Next
With R.Offset(RowOffset, ColumnOffset)
.NumberFormat = "@"
.Value = CellFormula
End With
Next
End Sub