Four Nested "IF" & "AND" conditional statement

avinashraste

Board Regular
Joined
Mar 12, 2008
Messages
167
Dear All,

I have a query which has four "IF"s & four "AND"s. I tried but it always results in some or the other error messages.

The query is like this -

if k="Short Sell" and m="Short Sell" Then "Short Sell"
if k="Short Sell" and m="Break Out" Then "Cover Shorts"
if k="Break Out" and m="Break Out" Then "Buy"
if k="Break Out" and m="Short Sell" Then "Cover Longs"

Please guide & help how to write this query in an excel cell.

Thanks & Regards

Avinash Raste
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
The query is like this -

if k="Short Sell" and m="Short Sell" Then "Short Sell"
if k="Short Sell" and m="Break Out" Then "Cover Shorts"
if k="Break Out" and m="Break Out" Then "Buy"
if k="Break Out" and m="Short Sell" Then "Cover Longs"

Not sure if this is what you are asking for but if k is in A1 and and m is in B1, I'd do this:

=IF(A1="Short Sell", IF(B1="Short Sell", "Short Sell", "Cover Shorts"), IF(B1="Short Sell", "Cover Longs", "Buy"))

This is assuming that "Short Sell" and "Break Out" are the only two values that will be in A1 and B1....

If not this...

=IF(A1="Short Sell", IF(B1="Short Sell", "Short Sell", IF(B1="Break Out", "Cover Shorts", ""), IF(A1="Break Out" , IF(B1="Short Sell", "Cover Longs", IF(B1="Break Out", "Buy", ""), "" ) )

Will leave it empty if there are other values possible.
 
Upvote 0
Dear BookWolf,

Thank You very much for your so promp reply. I tried your syntex, but it says "Too many arguments" & gives error.

You were perfectly right about my requirement. I will make it easy to judge ( I am sorry I did not put it in earlier post ) It is as below-

if k22=Short Sell and m22=Short Sell Then n22=Short Sell
if k22=Short Sell and m22=Break Out Then n22=Cover Shorts
if k22=Break Out and m22=Break Out Then n22=Buy
if k22=Break Out and m22=Short Sell Then n22=Cover Longs

Thanks & Regards

Avinash Raste
 
Upvote 0
Looks like I missed a few commas and end parathesis

=IF(k22="Short Sell", IF(m22="Short Sell", "Short Sell", IF(m22="Break Out", "Cover Shorts", "")), IF(k22="Break Out", IF(m22="Short Sell", "Cover Longs", IF(m22="Break Out", "Buy", "")),"" ) )
 
Upvote 0
Code:
=IF((K2="Short Sell")*(M2="Short Sell"),"Short Sell", IF((K2="Short Sell")*(M2="Break Out"),"Cover Shorts",IF((K2="Break Out")*(M2="Break Out"),"Buy","Cover Longs")))

lenze
 
Upvote 0
Dear BookWolf & Lanze

Thank you very much for your precious guidence & help. I tried your solution & it is working very much fine. This forum & its members are just amazing. The problem was so big for me, and only because of ur help it is solved in just a few moments. Thank you once again for sparing time & help me.

Thanks & Regards

Avinash Raste
 
Upvote 0

Forum statistics

Threads
1,214,886
Messages
6,122,093
Members
449,064
Latest member
Danger_SF

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