'IF statement to exclude blanks

I have a simple if statement to track yes/no for a pivot table. Sometimes this question does not apply and the user leaves it blank. When the field is blank the field defaults as no (2). If the field is blank I want the statement to ignore it. How do I do that?

=IF(K1239="Yes",1,2)

Picture of the excel spreadsheet



Solution 1:[1]

You should tell Excel supposed to do when the cell is empty

You can use IFS instead of IF function:

=IFS(A8="Yes","the value is YES",A8="No","the value is No",A8="","the value is Empty")

or

=IFS(A10="Yes",1,A10="No",2,A10="",0)

Or nested IF:

=IF(A11="Yes",1,IF(A11="No",2,0))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Míša Charvátová