I want to use the function IF() from Excel in a formula for some Cell, as shown below -

=IF(I2="SELL","(C2-F2)*D2","0")

Which means I want to see if Cell I2 has text- SELL in it (IF condition true), then I want the cell to have formula as (C2-F2)*D2, else if condition is false, it prints 0.

But trouble is that when condition is true, instead of putting the formula for the text it is putting the string (C2-F2)*D2 as it is in that Cell. What I want is that when condition is true, it should interpret (C2-F2)*D3 as formula in that cell. I tried many things , like -

=IF(I2="SELL","=((C2-F2)*D2)","0") 

or

=IF(I2="SELL","=("(C2-F2)*D2)"","0") 

but without any success.

link|improve this question

54% accept rate
Putting "" around "(C2-F2)*D2" changed it from a formula into a string. – bitslave Nov 25 '10 at 14:42
feedback

2 Answers

up vote 5 down vote accepted

=IF(I2="SELL",(C2-F2)*D2,0) will put the required calculated values in the cell. The formula is the complete one with the IF

As said by others = "..." just gives the string between the "" and Excel will not try to evaluate it.

link|improve this answer
Thank you, it works. – goldenmean Nov 25 '10 at 14:45
In excel quotation marks return the text between them rather than the results of the equation. This can be useful if you want to return a "Yes" from an IF statement, or as you have done use a "Sell" in the logical statement. – markfknight Jun 5 '11 at 10:34
feedback

"" will just paste a string.

Just use =IF(I2="SELL";(C2-F2)*D2;0)

link|improve this answer
May be typo , but it should not have semicolons, but commas as separators. – goldenmean Nov 25 '10 at 14:50
1  
Sorry, that's just that I use the Spanish version of MS Office – molgar Nov 25 '10 at 14:58
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.