Excel if value in range of values

In this example, the goal is to use a formula to check if a specific value exists in a range. The easiest way to do this is to use the COUNTIF function to count occurences of a value in a range, then use the count to create a final result.

COUNTIF function

The COUNTIF function counts cells that meet supplied criteria. The generic syntax looks like this:

=COUNTIF(range,criteria)

Range is the range of cells to test, and criteria is a condition that should be tested. COUNTIF returns the number of cells in range that meet the condition defined by criteria. If no cells meet criteria, COUNTIF returns zero. In the example shown, we can use COUNTIF to count the values we are looking for like this

COUNTIF(data,E5)

Once the named range data (B5:B16) and cell E5 have been evaluated, we have:

=COUNTIF(data,E5)
=COUNTIF(B5:B16,"Blue")
=1

COUNTIF returns 1 because «Blue» occurs in the range B5:B16 once. Next, we use the greater than operator (>) to run a simple test to force a TRUE or FALSE result:

=COUNTIF(data,B5)>0 // returns TRUE or FALSE

By itself, the formula above will return TRUE or FALSE. The last part of the problem is to return a «Yes» or «No» result. To handle this, we nest the formula above into the IF function like this:

=IF(COUNTIF(data,E5)>0,"Yes","No")

This is the formula shown in the worksheet above. As the formula is copied down, COUNTIF returns a count of the value in column E. If the count is greater than zero, the IF function returns «Yes». If the count is zero, IF returns «No».

Slightly abbreviated

It is possible to shorten this formula slightly and get the same result like this:

=IF(COUNTIF(data,E5),"Yes","No")

Here, we have remove the «>0» test. Instead, we simply return the count to IF as the logical_test. This works because Excel will treat any non-zero number as TRUE when the number is evaluated as a Boolean.

Testing for a partial match

To test a range to see if it contains a substring (a partial match), you can add a wildcard to the formula. For example, if you have a value to look for in cell C1, and you want to check the range A1:A100 for partial matches, you can configure COUNTIF to look for the value in C1 anywhere in a cell by concatenating asterisks on both sides:

=COUNTIF(A1:A100,"*"&C1&"*")>0

The asterisk (*) is a wildcard for one or more characters. By concatenating asterisks before and after the value in C1, the formula will count the text in C1 anywhere it appears in each cell of the range. To return «Yes» or «No», nest the formula inside the IF function as above.

An alternative formula using MATCH

As an alternative, you can use a formula that uses the MATCH function with the ISNUMBER function instead of COUNTIF:

=ISNUMBER(MATCH(value,range,0))

The MATCH function returns the position of a match (as a number) if found, and #N/A if not found. By wrapping MATCH inside ISNUMBER, the final result will be TRUE when MATCH finds a match and FALSE when MATCH returns #N/A.

EXPLANATION

This tutorial shows how to test if a range contains a specific value and return a specified value if the formula tests true or false, by using an Excel formula and VBA.

This tutorial provides one Excel method that can be applied to test if a range contains a specific value and return a specified value by using an Excel IF and COUNTIF functions. In this example, if the Excel COUNTIF function returns a value greater than 0, meaning the range has cells with a value of 500, the test is TRUE and the formula will return a «In Range» value. Alternatively, if the Excel COUNTIF function returns a value of of 0, meaning the range does not have cells with a value of 500, the test is FALSE and the formula will return a «Not in Range» value.

This tutorial provides one VBA method that can be applied to test if a range contains a specific value and return a specified value.

FORMULA
=IF(COUNTIF(range, value)>0, value_if_true, value_if_false)

ARGUMENTS
range: The range of cells you want to count from.
value: The value that is used to determine which of the cells should be counted, from a specified range, if the cells’ value is equal to this value.
value_if_true: Value to be returned if the range contains the specific value
value_if_false: Value to be returned if the range does not contains the specific value.

Many people usually asked that how to write an excel nested if statements based on multiple ranges of cells to return different values in a cell? How to nested if statement using date ranges? How to use nested if statement between different values in excel 2013 or 2016?

  • Nested IF statements based on multiple ranges
  • Nested IF Statement Using Date Ranges
  • Nested IF Statements For A Range Of Cells
  • Nested IF Statement between different values

This post will guide you how to understand excel nested if statements through some classic examples.

Table of Contents

  • Nested IF statements based on multiple ranges
  • Nested IF Statement Using Date Ranges
  • Nested IF Statements For A Range Of Cells
  • Nested IF Statement between different values
    • Related Functions

Nested IF statements based on multiple ranges

Assuming that you want to reflect the below request through nested if statements:

a) If 1<B1<0, Then return 0.1

b) If 0.99<B1<5, then return 0.15

c) If 4.99<B1<15, then return 0.2

d) If 14.99<B1<30, then return 0.5

So if B1 cell was “14.5”, then the formula should be returned “0.2” in the cell.

From above logic request, we can get that it need 4 if statements in the excel formula, and there are multiple ranges so that we can combine with logical function AND in the nested if statements.  The below is the nested if statements that I have tested.

=IF(AND(B1>0,B1<1),0.1,IF(AND(B1>0.99, B1<5),0.15, IF(AND(B1>4.99,B1<15),0.2, IF(AND(B1>14.99,B1<30),0.5,””))))

Nested if statements based on multiple ranges1

If you don’t want to use AND function in the above nested if statement, can try the below formula:

=IF(B1<1,0.1, If(B1<5,0.15,IF(B1<15,0.2,IF(B1<30,0.5,””))))

Nested if statements based on multiple ranges1

Nested IF Statement Using Date Ranges

I want to write a nested IF statement to calculated the right Quarter based one the criteria in the below table.

Nested If Statement Using Date Ranges1

According to the request, we need to compare date ranges, such as: if B1<E2<C1, then return A1.

So we can consider to use AND logical function in the nested if statement. The formula is as follows:

=IF(AND(E2>B1,E2<C1),A1,IF(AND(E2>B2,E2<C2),A2,IF(AND(E2>B3,E2<C3),A3,IF(AND(E2>B4,E2<C3),A4))))

Nested If Statement Using Date Ranges2

Or we can use INDEX function and combine with MATCH Function to get the right quarter.

=INDEX($A$1:$A$4,MATCH(E2,$B$1:$B$4,1))

Nested if statements based on multiple ranges3

Nested IF Statements For A Range Of Cells

If you have the following requirement and need to write a nested IF statement in excel:

If any of the cells A1 to C1 contain “excelhow”, then return “excelhow” in the cell E1.

If any of the cells A1 to C1 contain “google”, then return “excelhow” in the cell E1.

If any of the cells A1 to C1 contain “ibm”, then return “ibm” in the cell E1.

If any of the cells A1 to C1 contain “Cloud”, then return “ibm” in the cell E1.

How to check if cell ranges A1:C1 contain another string, using “COUNTIF” function is a good choice.

Countif function: Counts the number of cells within a range that meet the given criteria

Let’s try to test the below nested if statement:

=IF(OR(COUNTIF(A3:C3,"excelhow")>0,COUNTIF(A3:C3,"google")>0),"excelhow",IF(OR(COUNTIF(A3:C3,"ibm")>0,COUNTIF(A3:D3,"cloud")>0),"ibm",""))

Nested IF Statements For A Range Of Cells1

Nested IF Statement between different values

Assuming you have the following different range values, if the B1 has the value 65, then expected to return “under average”in cell C1, if the Cell B1 has the value 75, then return “average” in cell C1. And if the Cell B1 has the value 85, then return “above average” in the cell C1.

0-70 under average
71-80 average
81-100 above average

How do I format the nested if statement in Cell C1 to display the right value? Just try to use the below nested if function or using INDEX function.

=IF(B1< 0,"",IF(B1<= 70, "under average",IF(B1<=80, "Average", IF(B1<=100,"Above Average",""))))

Nested IF Statement between different values1


  • Excel IF function
    The Excel IF function perform a logical test to return one value if the condition is TRUE and return another value if the condition is FALSE. The IF function is a build-in function in Microsoft Excel and it is categorized as a Logical Function.The syntax of the IF function is as below:= IF (condition, [true_value], [false_value])….
  • Excel nested if function
    The nested IF function is formed by multiple if statements within one Excel if function. This excel nested if statement makes it possible for a single formula to take multiple actions…
  • Excel AND function
    The Excel AND function returns TRUE if all of arguments are TRUE, and it returns FALSE if any of arguments are FALSE.The syntax of the AND function is as below:= AND (condition1,[condition2],…) …
  • Excel COUNTIF function
    The Excel COUNTIF function will count the number of cells in a range that meet a given criteria.This function can be used to count the different kinds of cells with number, date, text values, blank, non-blanks, or containing specific characters.etc.The syntax of the COUNTIF function is as below:= COUNTIF (range, criteria) …
  • Excel INDEX function
    The Excel INDEX function returns a value from a table based on the index (row number and column number)The INDEX function is a build-in function in Microsoft Excel and it is categorized as a Lookup and Reference Function.The syntax of the INDEX function is as below:= INDEX (array, row_num,[column_num])…
  • Excel MATCH  function
    The Excel MATCH function search a value in an array and returns the position of that item.The MATCH function is a build-in function in Microsoft Excel and it is categorized as a Lookup and Reference Function.The syntax of the MATCH function is as below:= MATCH  (lookup_value, lookup_array, [match_type])….

Author: Oscar Cronquist Article last updated on February 17, 2023


In this article, I will demonstrate four different formulas that allow you to lookup a value that is to be found in a given range and return the corresponding value on the same row. If you need to return multiple values because the ranges overlap then read this article: Return multiple values if in range.

What’s on this page

  1. If value in range then return value — LOOKUP function
  2. If value in range then return value — INDEX + SUMPRODUCT + ROW
  3. If value in range then return value — VLOOKUP function
  4. If value in range then return value — INDEX + MATCH

They all have their pros and cons and I will discuss those in great detail, they can be applied to not only numerical ranges but also text ranges and date ranges as well.

I have made a video that explains the LOOKUP function in context to this article, if you are interested.

There is a file for you to get, at the end of this article, which contains all the formula examples in a worksheet each.

You can use the techniques described in this article to calculate discount percentages based on price intervals or linear results based on the lookup value.

Check out the LOOKUP category to find more interesting articles.

The following table shows the differences between the formulas presented in this article.

Formula Range sorted? Array formula Get value from any column? Two range columns?
LOOKUP Yes No Yes No
INDEX + SUMPRODUCT + ROW No No Yes Yes
VLOOKUP Yes No No No
INDEX + MATCH Yes No Yes No

Some formulas require you to have the lookup range sorted to function properly, the INDEX+SUMPRODUCT+ROW alternative is the only way to go if you can’t sort the values.

The disadvantage with the INDEX+SUMPRODUCT+ROW formula is that you need start and end values, the other formulas use the start values also as end range values.

The VLOOKUP function can only search the leftmost column, you must rearrange your table to meet this condition if you are going to use the VLOOKUP function.

1. If value in range then return value — LOOKUP function

To better demonstrate the LOOKUP function I am going to answer the following question.

Hi,

What type of formula could be used if you weren’t using a date range and your data was not concatenated?

ie: Input Value 1.78 should return a Value of B as it is between the values in Range1 and Range2

Range1 Range2 Value
1.33 1.66 A
1.67 1.99 B
2.00 2.33 C

The next image shows the table in greater detail.

The picture above shows data in cell range B3:C5, the search value is in C7 and the result is in C9.

Cell range B3:B5 must be sorted in ascending order for the LOOKUP function to work properly.

Ascending order means values are sorted from the smallest to the largest value. Example: 1,5,8,11.

If an exact match is not found the largest value is returned as long as it is smaller than the lookup value.

The LOOKUP function then returns a value in a column on the same row.

The formula in cell C9:

=LOOKUP(C8,B4:B6,C4:C6)

Example, Search value 1.71 has no exact match, the largest value that is smaller than 1.71 is 1.67. The returning value is found in column C on the same row as 1.67, in this case, B.

If the search value is smaller than the smallest value in the lookup range the function returns #N/A meaning Not Available or does not exist.

Example in the picture to the right, search value is 1 in the and the LOOKUP function returns #N/A.

To solve this problem simply add another number, for example 0. Cell range B3:B6 would then contain 0, 1.33, 1.67, 2.

A search value greater than the largest value in the lookup range matches the largest value. Example in above picture, search value is 3 and the returning value is C.

Watch video below to see how the LOOKUP function works:

Learn more about the LOOKUP function, recommended reading:

Recommended articles

test

Tip! — You can quickly sort a cell range, follow these steps:

  1. Press with right mouse button on on a cell in the cell range you want to sort
  2. Hover with mouse cursor over Sort
  3. Press with mouse on «Sort Smallest to Largest»

Back to top

2. If the value is in the range then return value — INDEX + SUMPRODUCT + ROW

The following formula is slightly larger but you don’t need to sort cell range B4:B6.

The formula in cell C11:

=INDEX(D4:D6, SUMPRODUCT(—($D$8<=C4:C6), —($D$8>=B4:B6), ROW(A1:A3)))

The ranges don’t need to be sorted however you need a start (Range1) and an end value (Range2).

Back to top

Explaining formula in cell C11

You can easily follow along, go to tab «Formulas» and press with left mouse button on «Evaluate Formula» button. Press with left mouse button on «Evaluate» button to move to next step.

Step 1 — Calculate first condition

The bolded part is the the logical expression I am going to explain in this step.

=INDEX(D4:D6, SUMPRODUCT(—($D$8<=C4:C6), —($D$8>=B4:B6), ROW(A1:A3)))

Logical operators

= equal sign
> less than sign
< greater than sign

The gretaer than sign combined with the equal sign <= means if value in cell D8 is smaller than or equal to the values in cell range C4:C6.

—($D$8<=C4:C6)

becomes

—(1,78<={1,66;1,99;2,33})

becomes

—{1,78<=1,66; 1,78<=1,99; 1,78<=2,33})

becomes

—({FALSE;TRUE;TRUE})

and returns {0;1;1}.

The double minus signs convert the boolean value TRUE or FALSE to the corresponding number 1 or 0 (zero).

Step 2 — Calculate second criterion

=INDEX(D4:D6, SUMPRODUCT(—($D$8<=C4:C6), —($D$8>=B4:B6), ROW(A1:A3)))

—($D$8>=B4:B6)

becomes

—(1,78>={1,33;1,67;2})

becomes

—({TRUE;TRUE;FALSE})

and returns

{1;1;0}

Step 3 — Create row numbers

=INDEX(D4:D6, SUMPRODUCT(—($D$8<=C4:C6), —($D$8>=B4:B6), ROW(A1:A3)))

ROW(A1:A3)

returns

{1;2;3}

Step 4 — Multiply criteria and row numbers and sum values

=INDEX(D4:D6, SUMPRODUCT(—($D$8<=C4:C6), —($D$8>=B4:B6), ROW(A1:A3)))

SUMPRODUCT(—($D$8<=C4:C6), —($D$8>=B4:B6), ROW(A1:A3))

becomes

SUMPRODUCT({0;1;1}, {1;1;0}, {1;2;3})

becomes

SUMPRODUCT({0;2;0})

and returns number 2.

Step 5 — Return a value of the cell at the intersection of a particular row and column

=INDEX(D4:D6, SUMPRODUCT(—($D$8<=C4:C6), —($D$8>=B4:B6), ROW(A1:A3)))

becomes

=INDEX(D4:D6, 2)

becomes

=INDEX({«A»;»B»;»C»}, 2)

and returns «B».

Functions in this formula: INDEX, SUMPRODUCT, ROW

Back to top

3. If value in range then return value — VLOOKUP function

=VLOOKUP($D$8,$B$4:$D$6,3,TRUE)

The VLOOKUP function requires the table to be sorted based on range1 in an ascending order.

Back to top

Explaining the VLOOKUP formula in cell C10

The VLOOKUP function looks for a value in the leftmost column of a table and then returns a value in the same row from a column you specify.

Arguments:
VLOOKUP(
lookup_value,
table_array,
col_index_num, [range_lookup]
)

The [range_lookup] argument is important in this case, it determines how the VLOOKUP function matches the lookup_value in the table_array.

The [range_lookup] is optional, it is either TRUE (default) or FALSE. It must be TRUE in our example here so that VLOOKUP returns an approximate match.

In order to do an approximate match the table_array must be sorted in an ascending order based on the first column.

=VLOOKUP($D$8,$B$4:$D$6,3,TRUE)

becomes

=VLOOKUP(1,78,{1,33, 1,66, «A»;1,67, 1,99, «B»;2, 2,33, «C»},3,TRUE)

1,67 is the next largest value and the VLOOKUP function returns «B».

Back to top

4. If value in range then return value — INDEX + MATCH

Formula in cell C10:

=INDEX($D$4:$D$6,MATCH(D8,$B$4:$B$6,1))

The lookup range must be sorted, just like the LOOKUP and VLOOKUP functions. Functions in this formula: INDEX and MATCH

Thanks JP!

Back to top

Explaining INDEX+MATCH in cell D10

=INDEX($D$4:$D$6,MATCH(D8,$B$4:$B$6,1))

Step 1 — Return the relative position of an item in an array

The MATCH function returns the relative position of an item in an array or cell range that matches a specified value

Arguments:
MATCH(
lookup_value,
lookup_array,
[match_type])
)

The [match_type] argument is optional. It can be either -1, 0, or 1. 1 is default value if omitted.

The match_type argument determines how the MATCH function matches the lookup_value with values in lookup_array.

We want it to do an approximate search so I am going to use 1 as the argument.

This will make the MATCH find the largest value that is less than or equal to lookup_value. However, the values in the lookup_array argument must be sorted in an ascending order.

To learn more about the [match_type] argument read the article about the MATCH function.

=INDEX($D$4:$D$6,MATCH(D8,$B$4:$B$6,1))

MATCH(D8,$B$4:$B$6,1)

becomes

MATCH(1.78,{1.33;1.67;2},1)

1.67 is the largest value that is less than or equal to lookup_value. 1.67 is the second value in the array. MATCH function returns 2.

Step 2 — Return a value of the cell at the intersection of a particular row and column

=INDEX($D$4:$D$6,MATCH(D8,$B$4:$B$6,1))

becomes

=INDEX($D$4:$D$6,2)

becomes

=INDEX({«A»;»B»;»C»},2)

and returns «B».

Back to top

Back to top

Quickly lookup a value in a numerical range

You can also do lookups in date ranges, dates in Excel are actually numbers.

I’ve got a range (A3:A10) that contains names, and I’d like to check if the contents of another cell (D1) matches one of the names in my list.

I’ve named the range A3:A10 ‘some_names’, and I’d like an excel formula that will give me True/False or 1/0 depending on the contents.

asked May 29, 2013 at 20:43

joseph.hainline's user avatar

joseph.hainlinejoseph.hainline

2,0523 gold badges16 silver badges16 bronze badges

=COUNTIF(some_names,D1)

should work (1 if the name is present — more if more than one instance).

answered May 29, 2013 at 20:47

pnuts's user avatar

1

My preferred answer (modified from Ian’s) is:

=COUNTIF(some_names,D1)>0

which returns TRUE if D1 is found in the range some_names at least once, or FALSE otherwise.

(COUNTIF returns an integer of how many times the criterion is found in the range)

pnuts's user avatar

pnuts

6,0623 gold badges27 silver badges41 bronze badges

answered Jun 6, 2013 at 20:40

joseph.hainline's user avatar

joseph.hainlinejoseph.hainline

2,0523 gold badges16 silver badges16 bronze badges

0

I know the OP specifically stated that the list came from a range of cells, but others might stumble upon this while looking for a specific range of values.

You can also look up on specific values, rather than a range using the MATCH function. This will give you the number where this matches (in this case, the second spot, so 2). It will return #N/A if there is no match.

=MATCH(4,{2,4,6,8},0)

You could also replace the first four with a cell. Put a 4 in cell A1 and type this into any other cell.

=MATCH(A1,{2,4,6,8},0)

CJBS's user avatar

answered Nov 10, 2014 at 22:57

RPh_Coder's user avatar

RPh_CoderRPh_Coder

4784 silver badges4 bronze badges

6

If you want to turn the countif into some other output (like boolean) you could also do:

=IF(COUNTIF(some_names,D1)>0, TRUE, FALSE)

Enjoy!

answered May 29, 2013 at 21:09

Ian McClellan's user avatar

1

For variety you can use MATCH, e.g.

=ISNUMBER(MATCH(D1,A3:A10,0))

answered May 29, 2013 at 23:28

barry houdini's user avatar

barry houdinibarry houdini

10.8k1 gold badge20 silver badges25 bronze badges

there is a nifty little trick returning Boolean in case range some_names could be specified explicitly such in "purple","red","blue","green","orange":

=OR("Red"={"purple","red","blue","green","orange"})

Note this is NOT an array formula

answered Jul 11, 2018 at 22:06

gregV's user avatar

gregVgregV

2042 silver badges4 bronze badges

1

You can nest --([range]=[cell]) in an IF, SUMIFS, or COUNTIFS argument. For example, IF(--($N$2:$N$23=D2),"in the list!","not in the list"). I believe this might use memory more efficiently.

Alternatively, you can wrap an ISERROR around a VLOOKUP, all wrapped around an IF statement. Like, IF( ISERROR ( VLOOKUP() ) , "not in the list" , "in the list!" ).

answered Dec 5, 2013 at 19:33

skilbjo's user avatar

0

In situations like this, I only want to be alerted to possible errors, so I would solve the situation this way …

=if(countif(some_names,D1)>0,"","MISSING")

Then I’d copy this formula from E1 to E100. If a value in the D column is not in the list, I’ll get the message MISSING but if the value exists, I get an empty cell. That makes the missing values stand out much more.

Dan Atkinson's user avatar

answered Aug 24, 2013 at 11:59

Catchoval's user avatar

0

Array Formula version (enter with Ctrl + Shift + Enter):

=OR(A3:A10=D1)

answered Dec 8, 2016 at 12:38

Slai's user avatar

SlaiSlai

1195 bronze badges

1

Home / Excel Formulas / Check IF a Value Exists in a Range

In Excel, to check if a value exists in a range or not, you can use the COUNTIF function, with the IF function. With COUNTIF you can check for the value and with IF, you can return a result value to show to the user. i.e., Yes or No, Found or Not Found.

In the following example, you have a list of names where you only have first names, and now, you need to check if “Arlene” is there or not.

list-of-names

You can use the following steps:

  1. First, you need to enter the IF function in cell B1.
    2-enter-the-if-function
  2. After that, in the first argument (logical test), you need to enter the COUNTIF function there.
    3-enter-the-count-if-function
  3. Now, in the COUNTIF function, refer to the range A1:A10.
    4-refer-to-a-range
  4. Next, in the criteria argument, enter “Glen” and close the parentheses for the COUNTIF Function.
    5-close-the-prentheses
  5. Additionally, use a greater than sign and enter a zero.
    6-use-greater-than-sign
  6. From here, enter a comma to go to the next argument in the IF, and enter “Yes” in the second argument.
    7-next-argument-in-if
  7. In the end, enter a comma and enter “No” in the third argument and type the closing parentheses.
    8-type-the-closing-prantheses

The moment you hit enter it returns “Yes”, as you have the value in the range that you have searched for.

returns-the-value
=IF(COUNTIF(A1:A10,"Glen")>0,"Yes","No")

How this Formula Works

This formula has two parts.

if-countif-formula

In the first part, we have COUNTIF, which counts the occurrence of the value in the range. And in the second part, you have the IF function that takes the values from the COUNTIF function.

So, if COUNTIF returns any value greater than which means the value is there in the range IF returns Yes. And if COUNTIF returns 0, which means the value is not there in the range and it returns No.

Check for a Value in a Range Partially

There counts to be a situation where you want to check for partial value from a range. In that case, you need to use wildcard characters (asterisk *).

In the following example, we have the same list of names but here is the full name. But we still need to look for the name “Glen”.

check-value-in-range-partially
=IF(COUNTIF(C1:C10,"*"&"Glen"&"*")>0,"Yes","No")

The value you want to search for needs to be enclosed with an asterisk, which we have used in the above example. This tells Excel, to check for the value “Glen” regardless of what is there before and after the value.

Download Sample File

  • Ready

And, if you want to Get Smarter than Your Colleagues check out these FREE COURSES to Learn Excel, Excel Skills, and Excel Tips and Tricks.

To perform complicated and powerful data analysis, you need to test various conditions at a single point in time. The data analysis might require logical tests also within these multiple conditions.

For this, you need to perform Excel if statement with multiple conditions or ranges that include various If functions in a single formula.

Those who use Excel daily are well versed with Excel If statement as it is one of the most-used formula. Here you can check various Excel If or statement, Nested If, AND function, Excel IF statements, and how to use them. We have also provided a VIDEO TUTORIAL for different If Statements.

There are various If statements available in Excel. You have to know which of the Excel If you will work at what condition. Here you can check multiple conditions where you can use Excel If statement.

1) Excel If Statement

Excel-If-functions

If you want to test a condition to get two outcomes then you can use this Excel If statement.

=If(Marks>=40, “Pass”)

2) Nested If Statement

Let’s take an example that met the below-mentioned condition

  • If the score is between 0 to 60, then Grade F
  • If the score is between 61 to 70, then Grade D
  • If the score is between 71 to 80, then Grade C
  • If the score is between 81 to 90, then Grade B
  • If the score is between 91 to 100, then Grade A

Then to test the condition the syntax of the formula becomes,

=If(B5<60, “F”,If(B5<71, “D”, If(B5<81,”C”,If(B5<91,”B”,”A”)

Nested-If-statement

3) Excel If with Logical Test

There are 2 different types of conditions AND and OR. You can use the IF statement in excel between two values in both these conditions to perform the logical test.

AND Function: If you are performing the logical test based on AND function, then excel will give you TRUE as an outcome in every condition else it will return false.

OR Function: If you are using OR condition for the logical test, then excel will give you an outcome as TRUE if any of the situations match else it returns false.

For this, multiple testing is to be done using AND and OR function, you should gain expertise in using either or both of these with IF statement. Here we have used if the function with 3 conditions.

How to apply IF & AND function in Excel

  • To perform this multiple if and statements in excel, we will take the data set for the student’s marks that contain fields such as English and Math’s Marks.
  • The score of the English subject is stored in the D column whereas the Maths score is stored in column E.
  • Let say a student passes the class if his or her score in English is greater than or equal to 20 and he or she scores more than 60 in Maths.
  • To create a report in matters of seconds, if formula combined with AND can suffice.
  • Type =IF( Excel will display the logical hint just below the cell F2. The parameters of this function are logical_test, value_if_true, value_if_false.
  • The first parameter contains the condition to be matched. You can use multiple If and AND conditions combined in this logical test.
  • In the second parameter, type the value that you want Excel to display if the condition is true. Similarly, in the third parameter type the value that will be displayed if your condition is false.Excel-if-statement-multiple-condition-range
  • Apply If & And formula, you will get =IF(AND(D2>=20,E2>=60),”Pass”,”Fail”).

If formula

  • Add Pass/Fail column in the current table.Excel-If-conditions
  • After you have applied this formula, you will find the result in the column.
  • Copy the formula from cell F2 and paste in all other cells from F3 to F13.Excel-If-And-statement

How to use If with Or function in Excel

To use If and Or statement excel, you need to apply a similar formula as you have applied for If & And with the only difference is that if any of the condition is true then it will show you True.

To apply the formula, you have to follow the above process. The formula is =IF((OR(D2>=20, E2>=60)), “Pass”, “Fail”). If the score is equal or greater than 20 for column D or the second score is equal or greater than 60 then the person is the pass.

How to Use If with And & Or function

If you want to test data based on several multiple conditions then you have to apply both And & Or functions at a single point in time. For example,

Situation 1: If column D>=20 and column E>=60

Situation 2: If column D>=15 and column E>=60

If any of the situations met, then the candidate is passed, else failed. The formula is

=IF(OR(AND(D2>=20, E2>=60), AND(D2>=20, E2>=60)), “Pass”, “Fail”).

4) Excel If Statement with other functions

Above we have learned how to use excel if statement multiple conditions range with And/Or functions. Now we will be going to learn Excel If Statement with other excel functions.

  • Excel If with Sum, Average, Min, and Max functions

Let’s take an example where we want to calculate the performance of any student with Poor, Satisfactory, and Good.

If the data set has a predefined structure that will not allow any of the modifications. Then you can add values with this If formula:

=If((A2+B2)>=50, “Good”, If((A2+B2)=>30, “Satisfactory”, “Poor”))

Using the Sum function,

=If(Sum(A2:B2)>=120, “Good”, If(Sum(A2:B2)>=100, “Satisfactory”, “Poor”))

Using the Average function,

=If(Average(A2:B2)>=40, “Good”, If(Average(A2:B2)>=25, “Satisfactory”, “Poor”))

Using Max/Min,

If you want to find out the highest scores, using the Max function. You can also find the lowest scores using the Min function.

=If(C2=Max($C$2:$C$10), “Best result”, “ “)

You can also find the lowest scores using the Min function.

=If(C2=Min($C$2:$C$10), “Worst result”, “ “)

If we combine both these formulas together, then we get

=If(C2=Max($C$2:$C$10), “Best result”, If(C2=Min($C$2:$C$10), “Worst result”, “ “))

You can also call it as nested if functions with other excel functions. To get a result, you can use these if functions with various different functions that are used in excel.

So there are four different ways and types of excel if statements, that you can use according to the situation or condition. Start using it today.

So this is all about Excel If statement multiple conditions ranges, you can also check how to add bullets in excel in our next post.

I hope you found this tutorial useful

You may also like the following Excel tutorials:

  • Multiple If Statements in Excel
  • Excel Logical test
  • How to Compare Two Columns in Excel (using VLOOKUP & IF)
  • Using IF Function with Dates in Excel (Easy Examples)

You can use the following formulas to check if a range in Excel contains a specific value:

Method 1: Check if Range Contains Value (Return TRUE or FALSE)

=COUNTIF(A1:A10,"this_value")>0

Method 2: Check if Range Contains Partial Value (Return TRUE or FALSE)

=COUNTIF(A1:A10,"*this_val*")>0

Method 3: Check if Range Contains Value (Return Custom Text)

=IF(COUNTIF(A1:A10,"this_value"),"Yes","No")

The following examples show how to use each formula in practice with the following dataset in Excel:

Example 1: Check if Range Contains Value (Return TRUE or FALSE)

We can use the following formula to check if the range of team names contains the value “Mavericks”:

=COUNTIF(A2:A15,"Mavericks")>0

The following screenshot shows how to use this formula in practice:

The formula returns FALSE since the value “Mavericks” does not exist in the range A2:A15.

Example 2: Check if Range Contains Partial Value (Return TRUE or FALSE)

We can use the following formula to check if the range of team names contains the partial value “avs” in any cell:

=COUNTIF(A2:A15,"*avs*")>0

The following screenshot shows how to use this formula in practice:

The formula returns TRUE since the partial value “avs” occurs in at least one cell in the range A2:A15.

Example 3: Check if Range Contains Value (Return Custom Text)

We can use the following formula to check if the range of team names contains the value “Hornets” in any cell and return either “Yes” or “No” as a result:

=IF(COUNTIF(A2:A15,"Hornets"),"Yes","No") 

The following screenshot shows how to use this formula in practice:

The formula returns No since the value “Hornets” does not occur in any cell in the range A2:A15.

Additional Resources

The following tutorials explain how to perform other common tasks in Excel:

How to Count Frequency of Text in Excel
How to Check if Cell Contains Text from List in Excel
How to Calculate Average If Cell Contains Text in Excel

So, there are times when you would like to know that a value is in a list or not. We have done this using VLOOKUP. But we can do the same thing using COUNTIF function too. So in this article, we will learn how to check if a values is in a list or not using various ways.

Check If Value In Range Using COUNTIF Function

So as we know, using COUNTIF function in excel we can know how many times a specific value occurs in a range. So if we count for a specific value in a range and its greater than zero, it would mean that it is in the range. Isn’t it?

Generic Formula

=COUNTIF(range,value)>0

Range: The range in which you want to check if the value exist in range or not.

Value: The value that you want to check in the range.

Let’s see an example:

Excel Find Value is in Range Example

For this example, we have below sample data. We need a check-in the cell D2, if the given item in C2 exists in range A2:A9 or say item list. If it’s there then, print TRUE else FALSE.
1
Write this formula in cell D2:

2
Since C2 contains “scale” and it’s not in the item list, it shows FALSE. Exactly as we wanted. Now if you replace “scale” with “Pencil” in the formula above, it’ll show TRUE.
3
Now, this TRUE and FALSE looks very back and white. How about customizing the output. I mean, how about we show, “found” or “not found” when value is in list and when it is not respectively.
Since this test gives us TRUE and FALSE, we can use it with IF function of excel.

Write this formula:

=IF(COUNTIF(A2:A9,C2)>0,»in List»,»Not in List»)

You will have this as your output.
4
What If you remove “>0” from this if formula?

=IF(COUNTIF(A2:A9,C2),»in List»,»Not in List»)

It will work fine. You will have same result as above. Why? Because IF function in excel treats any value greater than 0 as TRUE.

How to check if a value is in Range with Wild Card Operators

Sometimes you would want to know if there is any match of your item in the list or not. I mean when you don’t want an exact match but any match.

For example, if in the above-given list, you want to check if there is anything with “red”. To do so, write this formula.

=IF(COUNTIF(A2:A9,»*red*»),»in List»,»Not in List»)

This will return a TRUE since we have “red pen” in our list. If you replace red with pink it will return FALSE. Try it.
Now here I have hardcoded the value in list but if your value is in a cell, say in our favourite cell B2 then write this formula.

IF(COUNTIF(A2:A9,»*»&B2&»*»),»in List»,»Not in List»)

5
There’s one more way to do the same. We can use the MATCH function in excel to check if the column contains a value. Let’s see how.

Find if a Value is in a List Using MATCH Function

So as we all know that MATCH function in excel returns the index of a value if found, else returns #N/A error. So we can use the ISNUMBER to check if the function returns a number.
If it returns a number ISNUMBER will show TRUE, which means it’s found else FALSE, and you know what that means.

Write this formula in cell C2:

=ISNUMBER(MATCH(C2,A2:A9,0))

6
The MATCH function looks for an exact match of value in cell C2 in range A2:A9. Since DESK is on the list, it shows a TRUE value and FALSE for SCALE.

So yeah, these are the ways, using which you can find if a value is in the list or not and then take action on them as you like using IF function. I explained how to find value in a range in the best way possible. Let me know if you have any thoughts. The comments section is all yours.

Related Articles:

How to Check If Cell Contains Specific Text in Excel

How to Check A list of Texts In String in Excel

How to take the Average Difference between lists in Excel

How to Get Every Nth Value From A list in Excel

Popular Articles:

50 Excel Shortcuts to Increase Your Productivity

How to use the VLOOKUP Function in Excel

How to use the COUNTIF function in Excel

How to use the SUMIF Function in Excel

Понравилась статья? Поделить с друзьями:
  • Excel if value in cell is in a range
  • Excel if value format cell
  • Excel if value colour row
  • Excel if using words
  • Excel if two and