How to Use IF with OR Functions in Excel

スポンサーリンク
スポンサーリンク

Correct Usage of OR within IF Statements with Examples

By combining the IF function with the OR function in Excel, you can perform specific actions when at least one of multiple conditions is met. This article explains the basic syntax of IF and OR functions, the steps for usage, and practical examples.

Basic Syntax of IF and OR Functions

The basic syntax for combining the IF function with the OR function is as follows:

=IF(OR(condition1, condition2, …), result_if_TRUE, result_if_FALSE)

The OR function returns TRUE if any of the conditions are met, and FALSE if none of the conditions are satisfied.

Steps

  1. Select the cell where you want to use the IF and OR functions (e.g., C2).
  2. Enter the following formula to display a specific result when any condition is met:

Example Formula

For example, to display “OK” if the value in cell A2 is less than or equal to 10 or if the value in cell B2 is greater than or equal to 20, and “NG” otherwise, the formula is as follows:

=IF(OR(A2 <= 10, B2 >= 20), “OK”, “NG”)

Explanation of the Formula

  • A2 <= 10: Checks if the value in cell A2 is less than or equal to 10.
  • B2 >= 20: Checks if the value in cell B2 is greater than or equal to 20.
  • OR(A2 <= 10, B2 >= 20): Returns TRUE if either condition is met, and FALSE if neither condition is met.
  • IF(…, “OK”, “NG”): Displays “OK” if the OR function returns TRUE, and “NG” if it returns FALSE.

Example

In the table below, columns A and B contain numerical values, and column C displays “OK” if the value in column A is less than or equal to 10 or the value in column B is greater than or equal to 20. Otherwise, it displays “NG”.

A B C
1 Value 1 Value 2 Result
2 8 15 =IF(OR(A2 <= 10, B2 >= 20), “OK”, “NG”)
3 12 22 =IF(OR(A3 <= 10, B3 >= 20), “OK”, “NG”)
4 15 18 =IF(OR(A4 <= 10, B4 >= 20), “OK”, “NG”)
5 10 25 =IF(OR(A5 <= 10, B5 >= 20), “OK”, “NG”)

Results

  • Cell C2: Displays “OK” because A2 is less than or equal to 10.
  • Cell C3: Displays “OK” because B3 is greater than or equal to 20.
  • Cell C4: Displays “NG” because neither condition is met.
  • Cell C5: Displays “OK” because both A5 is less than or equal to 10 and B5 is greater than or equal to 20.

Explanation in a Programming Context

EXCEL JavaScript
=IF(OR(A2 <= 10, B2 >= 20), “OK”, “NG”)
if(A2<=10 || B2>=20){
  console.log("OK");
}else{
  console.log("NG");
}