# Four Nested "IF" & "AND" conditional statement

#### avinashraste

##### Board Regular
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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

#### BookWolf

##### New Member
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.

#### avinashraste

##### Board Regular
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

#### BookWolf

##### New Member
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", "")),"" ) )

#### lenze

##### Legend
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

#### avinashraste

##### Board Regular
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

Replies
0
Views
157
Replies
9
Views
462
Replies
0
Views
256
Replies
5
Views
168
Replies
6
Views
429

1,191,691
Messages
5,988,120
Members
440,126
Latest member
duque00

### 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.

### Which adblocker are you using?

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

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