# How to do an IF statement and an AND statement in same cell with different outcomes

#### Rmayfield

##### New Member
Trying to figure out how to do an IF statement and an AND statement in the same cell with different outcomes

Cell A1 has an X in it

Cell A2 has an X in it

Cell A3 has an X in it
Cell A4 has an X in it
Cell A5 has my formula

I want the formula to say if cell A1 and A2 have an X (A3 and A4 are blank), then return "Apple" in A5. If A1 and A3 have an X (A2 and A4 are blank), then return "Orange" in A5. If A1 and A4 have an X (A2 and A3 are blank), then return "Pear" in A5. If A1 is empty, then return blank in A5.

### Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

#### Fluff

##### MrExcel MVP, Moderator
Will those cells only have an X or be blank?

#### etaf

##### Well-known Member
=IF ( A1 = "", "", IF( AND ( A1 ="X", A2 ="X", A3 ="" , A4 ="" ) , "Apple", IF( AND ( A1 ="X", A2 ="", A3 ="X" , A4 ="" ) , "ORANGE", IF( AND ( A1 ="X", A2 ="", A3 ="" , A4 ="X" ) , "Pear" ))))

But that is how you asked, with the Logic in FULL

#### Rmayfield

##### New Member
Will those cells only have an X or be blank?
They will either have an X or be blank.

#### Fluff

##### MrExcel MVP, Moderator

In that case try etaf's solution, although it can be slimmed down slightly like
Excel Formula:
``=IF(A1="","",IF(AND(A2="X",A3="",A4=""),"Apple",IF(AND(A2="",A3="X",A4=""),"ORANGE",IF(AND(A2="",A3="",A4="X"),"Pear",""))))``

#### Rmayfield

##### New Member
In that case try etaf's solution, although it can be slimmed down slightly like
Excel Formula:
``=IF(A1="","",IF(AND(A2="X",A3="",A4=""),"Apple",IF(AND(A2="",A3="X",A4=""),"ORANGE",IF(AND(A2="",A3="",A4="X"),"Pear",""))))``
That did it! Thank you, thank you!

#### Fluff

##### MrExcel MVP, Moderator
Glad we could help & thanks for the feedback.

Replies
2
Views
109
Replies
3
Views
44
Replies
6
Views
592
Replies
4
Views
57
Replies
3
Views
165

### Forum statistics

1,140,995
Messages
5,703,619
Members
421,306
Latest member
ambuj Thakur ### 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