m.vesali
m.vesali

Reputation: 25

Use the text value in the Excel formula

I apologize for typing in English. This is a translator's achievement.
I want to come up with this formula but I can't.
A1 cell value is variable and can be one of these signs (=, <=,> =, <,>).
A3 and A4 cells also have numerical values.
Now the formula I am looking for in cell A2.

= if (A3 & A1 & A4,1,0)

So logical text can be one of the following:
A3 = A4 , A3 < A4 , A3 > A4 , A3 >= A4 , A3 <= A4
Is there a way for this formula?

Upvotes: 1

Views: 40

Answers (2)

Scott Craner
Scott Craner

Reputation: 152465

To do it with formula one must do all the combinations:

=IF(CHOOSE(MATCH(A1,{"=","<=",">=","<",">"},0),A3=A4, A3<=A4,A3>=A4, A3<A4,A3>A4),1,0)

enter image description here

Upvotes: 2

Gary&#39;s Student
Gary&#39;s Student

Reputation: 96753

We need an extra step. In A2 enter:

="=if(A3" & A1 & "A4 ,1,0)"

Example:

enter image description here

Sadly A2 is only a string and not a formula, but we can execute it. In a standard module, enter the following User Defined Function:

Function eval(s As String) As Variant
    Application.Volatile
    eval = Evaluate(s)
End Function

Pick another cell, say B2 and enter:

=eval(A2)

enter image description here

Whenever A1 or A3 or A4 are changed, the string-formula in A2 will change and the value in B2 will be re-calculated.

Upvotes: 1

Related Questions