ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Reading formulae in a different cell (https://www.excelbanter.com/excel-discussion-misc-queries/87004-reading-formulae-different-cell.html)

Albert

Reading formulae in a different cell
 
If cell A1 contains a formula e.g. =Vlookup(50,RANGE,2)=99.45 say, how can I
reference or find the 3rd argument in the formula from another cell. When I
use any formula that references A1 it always uses the result of the formula
(99.45 here) and not the text of the formula ( =vlookup(50.RANGE,2) ).

Thanks
--

Albert

Niek Otten

Reading formulae in a different cell
 
Hi Albert,

You can use this User Defined Function (UDF):

Function ShowFormula(a As Range)
If Application.ReferenceStyle = xlR1C1 _
Then ShowFormula = a.FormulaR1C1 _
Else: ShowFormula = a.Formula
End Function


--
Kind regards,

Niek Otten

"Albert" wrote in message ...
| If cell A1 contains a formula e.g. =Vlookup(50,RANGE,2)=99.45 say, how can I
| reference or find the 3rd argument in the formula from another cell. When I
| use any formula that references A1 it always uses the result of the formula
| (99.45 here) and not the text of the formula ( =vlookup(50.RANGE,2) ).
|
| Thanks
| --
|
| Albert



Gary''s Student

Reading formulae in a different cell
 
You could use a UDF to display the formula as a string and then parse the
string with MID(), LEFT(), etc.:

Function textofformula(r As Range) As String
textofformula = r.Formula
End Function



and use like =textofformula(A1)
--
Gary's Student


"Albert" wrote:

If cell A1 contains a formula e.g. =Vlookup(50,RANGE,2)=99.45 say, how can I
reference or find the 3rd argument in the formula from another cell. When I
use any formula that references A1 it always uses the result of the formula
(99.45 here) and not the text of the formula ( =vlookup(50.RANGE,2) ).

Thanks
--

Albert


Albert

Reading formulae in a different cell
 
Many thanks for your help.
--
Albert


"Niek Otten" wrote:

Hi Albert,

You can use this User Defined Function (UDF):

Function ShowFormula(a As Range)
If Application.ReferenceStyle = xlR1C1 _
Then ShowFormula = a.FormulaR1C1 _
Else: ShowFormula = a.Formula
End Function


--
Kind regards,

Niek Otten

"Albert" wrote in message ...
| If cell A1 contains a formula e.g. =Vlookup(50,RANGE,2)=99.45 say, how can I
| reference or find the 3rd argument in the formula from another cell. When I
| use any formula that references A1 it always uses the result of the formula
| (99.45 here) and not the text of the formula ( =vlookup(50.RANGE,2) ).
|
| Thanks
| --
|
| Albert





All times are GMT +1. The time now is 07:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com