Is there a way to fetch the text of a formula of another cell into an excel cell?

TomCon

Active Member
Joined
Mar 31, 2011
Messages
373
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
What i want is the equivalent of the VBA formula property, on the Excel sheet.
For instance in VBA i can say the following
x=Range("A1").formula
And it puts the text of the formula in cell A1 into the variable x.

I'd like to put the text of the formula in cell A1 into cell B1, say. Not as a formula, but as text. And with a formula, not by copy/paste. (I want to fill the formula down).

Is there a way?

Thank you.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
If you want to use a formula then I don't know how because I suspect that any formula you would use has to start with "=", thus negating the attempt to put a formula in a cell as text only. If you want to use vba then you could use range("B1")= "'" & .range(A1").formula
 
Upvote 0
First of all this could be solved with a UDF written in VBA.

But i really try hard to avoid UDFs as they are called way too often, unnecessarily, even when non-volatile. This can be seen by putting a breakpoint in a UDF and then entering a value in a random empty cell in a workbook unconnected to the UDF (no other cell in the workbook is dependent on this cell) and you will see the UDF is called...many times. It has greatly impacted (reduced) my use of UDFs.

I want to parse the formula of one cell and put a parsed result in another cell (without using a UDF!).

For example.
If A1 contains
=SUM(H1000:H1500)
I want the number "1000" to be the result.

So, in psuedo code it might look like this
=VALUE( MID(formula text in A1, FIND( "H", formula text in A1)+1, 4))

Thanks if any ideas!
 
Upvote 0
Never have seen that behaviour and have done lots of debugging while trying to learn. I could envision what you're saying if the code was in personal workbook though. Sometimes though, a guy's gotta do what a guy's gotta do. At least now if you get a formula solution I'll know that referring to a range formula can be done in a formula.

Maybe the built in FormulaText function if you have the right Excel version?
 
Upvote 0
So if you have it that function, this will find "4" from B4
=MID(FORMULATEXT(E4),FIND("B",FORMULATEXT(E4),1)+1,1)
E4 contains =DAY(EOMONTH(B4,0))

but it's not at all volatile. Not sure how you get 1000 out of H1000 one time, 100 if it's H100, 10 if it's H10 etc. to say nothing of changing column letters.
 
Upvote 0
Solution
Wow thanks, that is what i was looking for, the Excel built-in function FORMULATEXT. I googled various things but it did not turn up. Guess i did not describe it exactly enough for that to turn up as an answer. But, thanks much! Always want to avoid UDFs (as outlined above)!
Tom
 
Upvote 0
So if you have it that function, this will find "4" from B4
Well that wasn't good grammar was it? How about "So if you have it, that function will find "4" from B4"
Glad I could help. FWIW, I think my search term was "excel formula to get a cell formula" which led me to
Baring my soul here - google is how I manage to answer some 75% of the questions I respond to.
Thanks for the recognition.
 
Upvote 0

Forum statistics

Threads
1,215,136
Messages
6,123,247
Members
449,093
Latest member
Vincent Khandagale

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