Is this the best way to extract the cell address from a FormulaText expression?

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,687
Office Version
  1. 365
Platform
  1. Windows
Before the FormulaText function was available, I wrote my own little GetFormula UDF. (See below) It had an optional second parameter that would include the cell address before the formula text. I found that very helpful as I often needed to put the GetFormula calls somewhere other than right next to the cell in question.

The FormulaText function lacks this option. I'll probably rewrite my GetFormula UDF to make use of the new FormulaText function. In the meantime, I came up with this solution. Is there a better way? I am referring to the expressions in D2:D4. My formula text really threw xl2bb a curve. 😯🤨

Cell Formulas
RangeFormula
D2:D4D2=LET(txt,FORMULATEXT(E2),NLeft,FIND("(",txt,1)+1,MID(txt,NLeft,LEN(txt)-NLeft))
E2E2=FORMULATEXT(F8)
E3E3=FORMULATEXT(H8)
E4E4=FORMULATEXT(J8)
E8:E17E8=LET(ridx,ROW()-ROW(Table14[#Headers]),SUM(DROP(TAKE(Table14[Value],ridx),MAX(0,ridx-N))))
F8:F17F8=LET(ridx,ROW()-ROW(Table14[#Headers]),AVERAGE(DROP(TAKE(Table14[Value],ridx),MAX(0,ridx-N))))
G8:G17G8=LET(ridx,ROW()-ROW(Table14[#Headers]),SUM(INDEX(Table14[Value],SEQUENCE(MIN(ridx,N),,ridx,-1))))
H8:H17H8=LET(ridx,ROW()-ROW(Table14[#Headers]),AVERAGE(INDEX(Table14[Value],SEQUENCE(MIN(ridx,N),,ridx,-1))))
I8:I17I8=MAP(SEQUENCE(ROWS(Table14)),LAMBDA(r,SUM(DROP(TAKE(Table14[Value],r),MAX(0,r-N)))))
J8:J17J8=MAP(SEQUENCE(ROWS(Table14)),LAMBDA(r,AVERAGE(DROP(TAKE(Table14[Value],r),MAX(0,r-N)))))
Dynamic array formulas.
Named Ranges
NameRefers ToCells
N=MrExcel!$C$6I8:J8, E8:H17



Here's my GetFormula UDF:

Excel Formula:
Function GetFormula(pCell As Range, Optional pAddrSw As Boolean = True) As String

GetFormula = pCell(1).FormulaArray      'Get the formula in the cell
If pCell(1).HasArray Then               'If it's an array formula,
  GetFormula = "{" & GetFormula & "}"     'Add the {}s
End If
                                        
If pAddrSw Then                         'If switch is on
  GetFormula = pCell(1).Address(0, 0) & ": " & _
    pCell(1).PrefixCharacter & GetFormula 'Add the cell address and leading quote, if any
End If

End Function
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
You could use the ADDRESS() function:
Cell Formulas
RangeFormula
I2:I5I2=1+1
J2,J4:J5J2=ADDRESS(ROW(I2),COLUMN(I2),ROW()-1)&" "&FORMULATEXT(I2)
J3J3=ADDRESS(ROW(I3),COLUMN(I3),ROW()-1)&" "& FORMULATEXT(I3)
 
Upvote 0
Solution
You could use the ADDRESS() function:
Of course. Why didn't I think of that? doh 🤔🤨😡

But I don't understand your 3rd parameter. Why not a literal?

Take Function.xlsx
NO
93$N$9: =1+2
107N$10: =3+4
1111$N11: =5+6
1215N12: =7+8
MrExcel
Cell Formulas
RangeFormula
N9N9=1+2
O9O9=ADDRESS(ROW(N9),COLUMN(N9),1)&": "&FORMULATEXT(N9)
N10N10=3+4
O10O10=ADDRESS(ROW(N10),COLUMN(N10),2)&": "&FORMULATEXT(N10)
N11N11=5+6
O11O11=ADDRESS(ROW(N11),COLUMN(N11),3)&": "&FORMULATEXT(N11)
N12N12=7+8
O12O12=ADDRESS(ROW(N12),COLUMN(N12),4)&": "&FORMULATEXT(N12)
 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,989
Members
452,541
Latest member
haasro02

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