# If statement

#### hayati

##### Board Regular
Hi,

Need some help with an if statement I am working on. Here are the conditions:

1) If A1 = NP then S
2) If A1 = PH and A2 = PD then P
3) If A1 = PH and A2 NOT PD then S
4) If A1 = PD then C

There are only three variables NP, PH,PD

An example:

Column A Column B
NP s
PH p
PD c
PD c
PD c
PH s
NP s
PH p
PD c

Currently I have:

=IF(A8="NP","s",IF(AND(A8="PH",A9="PD"),"p",IF(AND(A8="PH",OR(A9="PH",A9="NP")),"s",IF(A8="PD","c"))))

But I think there must be a better way to do it?

Any thoughts?

Cheers
Matt

### Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

#### Peter_SSs

##### MrExcel MVP, Moderator
hayati

IF NP, PH & PD are the only values allowed in A1 then try:
=IF(A1="NP","S",IF(A1="PD","C",IF(A2="PD","P","S")))

#### Yogi Anand

##### MrExcel MVP
Hi hayati:

=IF(A1="NP","S",IF(A1="PH",IF(A2="PD","P","S"),IF(A1="PD","C")))

#### hayati

##### Board Regular
Thanks!

Hi gents,

Thanks, I knew there could be a better way of stating that.

Both formulas work like a charm!

Cheers,
Matt

Replies
6
Views
160
Replies
4
Views
318
Replies
0
Views
137
Replies
2
Views
145
Replies
21
Views
630

1,195,600
Messages
6,010,651
Members
441,558
Latest member
lambierules

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