Home » excel » how to use IF to pick out codes excel?

how to use IF to pick out codes excel?

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have a column of codes and I specifically want to extract ANY of these codes with Excel’s IF function.

I wrote this code and it did not work: =IF(OR(O2={"6122";"6124";"6200";"6197"});1;0)

How can I use the IF function or other function to pick out any of the above codes?

EDIT: the code itself works but it does not return 1 when it hits any of the specified codes.

How to&Answers:

Check the value in cell O2. If it is text, then your formula will work. If the value in cell O2 is a number like 6122, then your formula will not work, since it is explicitly looking for a text value of “6122” and the other text values.

Data type matters. The text “6122” is not the same as the numeric value 6122.

You can alleviate the issue by coercing the value in O2 to a number and forcing a numeric comparison with

=IF(OR(O2+0={6122,6124,6200,6197}),1,0)

(if your regional settings use the semicolon ; as a list separator, please replace the commas in the above formula with semicolons)

This will work if O2 is either text or numeric. The values to compare with are numbers.

So, determine what data type is stored in cell O2 and make sure that you compare it with a suitable data type in your formula.