26

How do you do an IF ... OR ... THEN statement in a Google spreadsheet? In PHP I would do this:

if($C7 == "U.S.A." || $C7 == "Canada"){ ...

How to do the same as a spreadsheet formula?

At the moment I have

= IF ( C7 = "U.S.A." , "The Americas" , "Europe" )

I'd like to say if C7 = "U.S.A." OR "Canada"...

NB: I should have been able to (and tried extensively to) Google this, but the search engine ignores the words IF and OR

0

2 Answers 2

38

In Google Spreadsheets, OR is a function (with any number of arguments), so you would write

IF (OR(C7 = "U.S.A."; C7 = "Canada"); "The Americas"; "Europe")

See the example spreadsheet I set up.

Also, check the Google Spreadsheets function list.

Note that my example code uses ; - you might have to use ,, depending on your locale settings.

0
1

If you have longer statement,you can use regexmatch() instead.

regexmatch(C7,"(U.S.A.|Canada|Other_area_name|Other_area_name2|Other_area_name3)")

separated by adding | symbol.

For more complicated use,see the official documents.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.