# How to use the OR function

**What is the OR function?**

The OR function allows you to carry out a logical test in each argument and if at least one argument returns TRUE the OR function returns TRUE.

If all arguments return FALSE the OR function also returns FALSE.

**What is a logical test?**

A logical test in Excel is a test or condition that results in either a TRUE or FALSE outcome. Logical tests are essential for conditional formatting, data validation, formulas, filters, and more. Mastering logical tests unlocks a lot of functionality in Excel. Comparison operators let you build logical tests in Excel formulas.

Here is an example of a logical test:

A1<B1

A1 and B1 are relative cell references. < is a comparison operator that allows you to check if a value is smaller than another value.

If A1 contains 5 and B1 contains 4 the logical expression becomes 5<4 which returns the Boolean value FALSE because 5 is NOT smaller than 4.

**What are comparison operators?**

Comparison operators are the equal sign, larger than, and the smaller than signs.

- = equal sign
- > larger than
- < smaller than

You can combine comparison operators to create more types of logical tests.

- <= larger than or equal to
- >=smaller than or equal to
- <> not equal to

Here is an example that carries out two logical tests, one in each argument.

=OR(5<4, 4<5)

The first argument contains 5<4 and that returns FALSE, the second argument is 4<5 which returns TRUE.

=OR(FALSE,TRUE)

The OR function performs OR logic between the arguments and returns TRUE.

**What is OR logic?**

OR logic is a boolean logic function that results in TRUE if any of the inputs are TRUE. It returns FALSE if all inputs are FALSE.

OR(TRUE, TRUE) = TRUE

OR(TRUE, FALSE) = TRUE

OR(FALSE, TRUE) = TRUE

OR(FALSE, FALSE) = FALSE

**What is TRUE and FALSE?**

TRUE and FALSE are Boolean values, logical test return a Boolean value or their numerical equivalents.

**What are the numerical equivalents to TRUE and FALSE?**

The numerical equivalents to TRUE and FALSE are 1 and 0 (zero) respectively.

### Table of Contents

- OR function syntax
- OR function arguments
- OR Function Example
- Boolean values
- OR function - multiple conditions
- OR function not working
- OR function array
- OR function COUNTIF
- OR function with IF
- OR function contains text
- OR function conditional formatting
- How to filter using OR logic between columns - Autofilter and Excel tables
- Get Excel file

## 1. OR function syntax

OR(*logical1*, *[logical2]*)

The or function is a logical function, it allows you to evaluate multiple conditions.

It can be used instead of nested IF functions. The OR function is even more versatile if you combine it with the AND function, there is an example below using both the OR and AND functions.

## 2. OR function arguments

logical1 |
Required. A logical expression that returns a logical value or a number. |

[logical2] |
Optional. You can have up to 254 additional arguments. |

## 3. OR Function Example

Formula in cell D3:

The picture above shows the formula in column D, it returns TRUE in cell D3, D4 and D5 because the amount is below 10.

## 4. Boolean arguments

The OR function arguments can result in TRUE or FALSE, however, it also treats all numbers, both positive and negative, as TRUE.

The exception to that is 0 (zero) which is treated the same as FALSE.

Formula in cell B3:

Formula in cell B3 returns TRUE. TRUE exists at least once.

Formula in cell B4:

Formula in cell B4 returns TRUE.

Formula in cell B5:

Formula in cell B4 returns FALSE. All arguments are FALSe, OR function returns FALSE.

Formula in cell B6:

The numerical equivalent to TRUE is any number other than 0 (zero). 1 is therefore TRUE. Formula in cell B6 returns TRUE.

Formula in cell C3:

The same goes for negative values. -1 is TRUE.

Formula in cell C3:

23, 55 and -34 are all TRUE.

Formula in cell C3:

0 (zero) is FALSE. All arguments are FALSE, OR function returns FALSE.

Formula in cell C3:

All numbers are not zero, they all evaluate to TRUE.

## 5. OR function - multiple conditions

The array formula in cell C3 performs two logical tests. If the value in cell B3 is equal to cell E3 or E4 the formula returns TRUE.

Formula in cell C3:

The technique used in column C that compares a value to multiple values using a cell range instead of declaring each logical expression in an argument saves you time and effort. The downside is that you need to enter the formula as an array formula unless you use Excel 365.

To enter the formula above as an array formula, type the formula in a cell. Press and hold CTRL + SHIFT keys simultaneously, then press Enter once. Release all keys.

The formula is now enclosed with curly brackets, they indicate you successfully entered the formula as an array formula. Don't enter the curly brackets yourself.

### 5.1 Explaining formula in cell C3

#### Step 1 - Reference conditions

You will be using the same conditions in cell C3 and cells below, it is a good idea to create absolute references meaning they won't change when you copy the cell and paste to cells below.

The dollar sign $ lets you lock both column and row references, see reference below.

$E$3:$E$4

returns {"Binder";"Printer"}. The curly brackets tell you that this is an array of values, they can have a comma or semicolon delimiting character or both.

#### Step 2 - Compare conditions with cell value

The equal sign is a logical operator that lets you compare value to value or in this case value to values. It returns a boolean value TRUE or FALSE.

$E$3:$E$4=B3

becomes

{"Binder";"Printer"}="Stapler"

and returns {FALSE; FALSE}. None of the conditions match the value in cell B3.

#### Step 3 - Evaluate OR function

The OR function returns TRUE if at least one of the boolean values in the array is TRUE.

OR($E$3:$E$4=B3)

becomes

OR({FALSE; FALSE})

and returns FALSE.

## 6. OR function not working

The OR function returns an error value if it's not working properly. Press with the mouse on the exclamation mark and a pop-up menu appears.

Press with the mouse on "Help on this error". It will take you to the Microsoft website where you can troubleshoot the formula further.

### 6.1 #NAME! error

The name error occurs if you misspelled a function. Check the formula in the formula bar. In the example above the OR function is wrong.

### 6.2 Calculation

Check that the calculation options are set to automatic.

Go to top formulas. On the ribbon. Press with left mouse button on the calculation options button. A pop-up menu appears, select "Automatic".

### 6.3 #VALUE! error

Formula in cell D3:

The or function returns a value error if one of the arguments is not a Boolean value or numerical value.

## 7. OR function array

The array formula in cell D3 evaluates two logical expressions. If the value in cell B3 is equal to any of the conditions in cells B9:B11 **and** the value in cell C2 is equal to any of the numbers in cells C9:C10 the formula returns TRUE.

Formula in cell D3:

Cell B3 is equal to a condition in cell B9 and cell C3 is equal to C10, the formula returns TRUE in cell D3.

### 7.1 Explaining formula in cell C3

#### Step 1 - Compare values

The equal sign is a logical operator that lets you compare value to value or in this case value to values. It returns a boolean value TRUE or FALSE.

$B$9:$B$11=B3

becomes

{"Stapler";"Calculator";"Ballpoint pen"}="Stapler"

and returns

{TRUE; FALSE; FALSE}.

#### Step 2 - Check if any of the conditions match cell B3

The OR function returns TRUE if at least one of the boolean values in the array is TRUE.

OR($B$9:$B$11=B3)

becomes

OR({TRUE; FALSE; FALSE})

and returns TRUE.

#### Step 3 - Check next cell C3

OR($C$9:$C$10=C3)

becomes

OR({19;2}=2)

becomes

OR({FALSE; TRUE})

and returns TRUE.

#### Step 4 - Check that all conditions evaluate to TRUE

The AND function returns TRUE if all arguments evaluate to TRUE.

AND(OR($B$9:$B$11=B3),OR($C$9:$C$10=C3))

becomes

AND(TRUE, TRUE)

and returns TRUE.

## 8. OR function COUNTIF

The array formula in cell D3 evaluates two logical expressions. If the value in cell B3 is equal to any of the conditions in cells B9:B11 **or** the value in cell C3 is equal to any of the numbers in cells C9:C11 the formula returns TRUE.

Formula in cell D3:

Cell B3 is equal to a condition in cell B9 and cell C3 is not equal to any of the conditions in cells C9:C11, the formula returns TRUE in cell D3.

### 8.1 Explaining formula in cell C3

#### Step 1 - Count values based on first conditions

The COUNTIF function counts the number of cells that meet the condition.

COUNTIF(*range*, *criteria*)

COUNTIF(B3,$B$9:$B$11)

becomes

COUNTIF("Stapler", {"Stapler"; "Calculator"; "Ballpoint pen"})

and returns {1; 0; 0}.

#### Step 2 - Count values based on second conditions

COUNTIF(C3,$C$9:$C$11)

becomes

COUNTIF(2, {19; 3; 8})

and returns {0; 0; 0}.

#### Step 3 - Count values

The OR function returns TRUE if at least one value is TRUE.

OR(COUNTIF(B3,$B$9:$B$11), COUNTIF(C3,$C$9:$C$11))

becomes

OR({1; 0; 0}, {0; 0; 0})

and returns TRUE. 1 is the numerical equivalent to TRUE.

## 9. OR function with IF

Formula in cell D3:

### 9.1 Explaining formula in cell C3

#### Step 1 - Check the first condition

The larger than character is a logical operator, it checks if a value is larger than another value. It returns boolean value TRUE or FALSE.

C3>5

becomes

11>5

and returns TRUE.

#### Step 2 - Check the second condition

The smaller than character is a logical operator, it checks if a value is smaller than another value. It returns boolean value TRUE or FALSE.

C3<1

becomes

11<1

and returns FALSE.

#### Step 3 - Evaluate OR function

OR(C3>5,C3<1)

becomes

OR(TRUE, FALSE)

and returns TRUE.

#### Step 4 - Evaluate IF function

The IF function returns one value if the logical test is TRUE and another value if the logical test is FALSE.

IF(*logical_test*, [*value_if_true*], [*value_if_false*])

IF(OR(C3>5,C3<1),B3,"")

## 10. OR function contains text

Formula in cell D3:

### 10.1 Explaining formula in cell C3

#### Step 1 - Search value for strings

The SEARCH function returns the position of the character at which a specific text string is found. Luckily the IF function accepts any number as TRUE except 0 (zero), however, the SEARCH function returns an error #VALUE! if it can't find the text string.

SEARCH($E$3:$E$4,B3)

becomes

SEARCH({"pen";"ap"},"Stapler")

and returns {#VALUE!; 3}.

#### Step 2 - Check if number

To avoid the error value I use the ISNUMBER function that returns TRUE if a number and FALSE if anything else, also formula errors.

ISNUMBER(SEARCH($E$3:$E$4,B3))

becomes

ISNUMBER({#VALUE!; 3})

and returns {FALSE; TRUE}

#### Step 3 - Evaluate OR function

OR(ISNUMBER(SEARCH($E$3:$E$4,B3)))

becomes

OR({FALSE; TRUE})

and returns TRUE.

#### Step 3 - Evaluate IF function

The IF function returns one value if the logical test is TRUE and another value if the logical test is FALSE.

IF(*logical_test*, [*value_if_true*], [*value_if_false*])

IF(OR(ISNUMBER(SEARCH($E$3:$E$4,B3))),B3,"")

becomes

IF(TRUE,B3,"")

and returns "Stapler".

## 11. OR function Conditional Formatting

The image above shows Conditional Formatting highlgihting cells in ceolumn B if they match the conditions specified in column D.

Conditional formatting formula applied to cell range B3:B8:

### 11.1 Explaining conditional formatting formula

#### Step 1 - Define reference to conditions

This reference must stay unchanged or locked to D3:D4, use the dollar sign character to lock a reference for both column and row.

$D$3:$D$4

#### Step 2 - Compare values

The equal sign is a logical operator that lets you compare value to value or in this case value to values. It returns a boolean value TRUE or FALSE.

B3=$D$3:$D$4

becomes

"Stapler"={"Printer"; "Ruler"}

and returns {FALSE; FALSE}

#### Step 3 - Evaluate logical tests

OR(B3=$D$3:$D$4)

becomes

OR({FALSE; FALSE})

and returns FALSE.

### 11.2 How to apply Conditional formatting

How to apply Conditional Formatting

## 12. How to filter using OR logic between columns - Autofilter and Excel tables

The filter feature in Excel won't allow you to do OR logic between columns, however, you can if you allow assistance from a formula.

I want to filter all rows where Category is equal to 1 OR Size is equal to A, the formula in E3 is:

Alternative formula:

Copy the formula and paste to cells below.

Now it is time to apply a filter to your data set. Go to tab "Data" on the ribbon, press with left mouse button on "Filter" button or press CTRL + SHIFT + L.

Arrows appear on your headers, see picture below.

Press with mouse on the arrow next to "Formula" header and deselect 0 (zero). If you use the alternative formula, simply deselect False.

Press with left mouse button on "OK" button. Here is the filtered table.

To remove the filter simply press with left mouse button on the "Clear" button on the ribbon.

## 13. Get Excel *.xlsx file

### 'OR' function examples

Table of Contents Automate net asset value (NAV) calculation on your stock portfolio Calculate your stock portfolio performance with Net […]

Table of Contents Excel monthly calendar - VBA Calendar Drop down lists Headers Calculating dates (formula) Conditional formatting Today Dates […]

The image above shows the performance across industry groups for different date ranges, conditional formatting makes the table much easier […]

### Functions in 'Logical' category

The OR function function is one of 17 functions in the 'Logical' category.

## How to comment

How to add a formula to your comment<code>Insert your formula here.</code>

Convert less than and larger than signsUse html character entities instead of less than and larger than signs.

< becomes < and > becomes >

How to add VBA code to your comment[vb 1="vbnet" language=","]

Put your VBA code here.

[/vb]

How to add a picture to your comment:Upload picture to postimage.org or imgur

Paste image link to your comment.

Contact OscarYou can contact me through this contact form