0

I am trying to make a logical operator variable (>,<,=) based on the user's input.

My main goal is to add a string of text as the logical expression of an if statement. For example I want to take =(A22&A23&A24) which will yield 3>2 in cell A26.

Then I want to take the text of A26 and place it into an if statement:

=IF(A26, True, False) which if I were to just type in 3>2 would give me True. However I just get #VALUE. I've tried converting it to text, copy and pasting it with just the values but I always get #VALUE.

Any ideas?

  • Excel will not evaluate text strings as formulas. You will need to write a User Defined Function to do that. And I cannot reproduce typing `3>2` into `A26`, and having that formula of yours return `TRUE`. Rather it returns `#VALUE!` – Ron Rosenfeld Jun 16 '16 at 16:34
  • I just meant if I type in =IF(3>2, True, False) it will return True – ncastellucci Jun 16 '16 at 16:37

1 Answers1

0

You will probably need VBA, Indirect() won't work, AFAIK.

Enter this into a workbook module:

Function Eval(Ref As String)
Application.Volatile
Eval = Evaluate(Ref)
End Function

Then, you can do =If(eval(A26),True,False).

(Thanks to @Fionnuala)

Community
  • 1
  • 1
BruceWayne
  • 22,923
  • 15
  • 65
  • 110
  • This should be a comment if you're gonna copy verbatim XD – findwindow Jun 16 '16 at 16:43
  • Holy Hallelujah Batman! It worked! Just for anyone else's reference you need to name the Eval or else you will get an ambiguous error – ncastellucci Jun 16 '16 at 16:48
  • @findwindow - Ah, sorry, should I just make these comments if it's basically someone else's answer? Or should we flag the question as duplicate? – BruceWayne Jun 16 '16 at 17:17
  • 1
    Well, we rarely flag duplicates even though the majority of questions on SO has been answered in some variation XD – findwindow Jun 16 '16 at 18:42