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.
You can use the following steps:
- First, you need to enter the IF function in cell B1.
- After that, in the first argument (logical test), you need to enter the COUNTIF function there.
- Now, in the COUNTIF function, refer to the range A1:A10.
- Next, in the criteria argument, enter “Glen” and close the parentheses for the COUNTIF Function.
- Additionally, use a greater than sign and enter a zero.
- From here, enter a comma to go to the next argument in the IF, and enter “Yes” in the second argument.
- In the end, enter a comma and enter “No” in the third argument and type the closing parentheses.
The moment you hit enter it returns “Yes”, as you have the value in the range that you have searched for.
=IF(COUNTIF(A1:A10,"Glen")>0,"Yes","No")
How this Formula Works
This formula has two parts.
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”.
=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.
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
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.
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.
Write this formula in cell D2:
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.
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.
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»)
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))
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
Return to Excel Formulas List
Download Example Workbook
Download the example workbook
This tutorial demonstrates how to use the COUNTIF function to determine if a value exists in a range.
COUNTIF Value Exists in a Range
To test if a value exists in a range, we can use the COUNTIF Function:
=COUNTIF(Range, Criteria)>0
The COUNTIF function counts the number of times a condition is met. We can use the COUNTIF function to count the number of times a value appears in a range. If COUNTIF returns greater than 0, that means that value exists.
=COUNTIF($E$3:$E$9,B3)
By attaching “>0” to the end of the COUNTIF Function, we test if the function returns >0. If so, the formula returns TRUE (the value exists).
=COUNTIF($E$3:$E$9,B3)>0
You can see above that the formula results in a TRUE statement for the name “Patrick Mitchell. On the other hand, the name “Georgia Smith” and “Patrick Svensen” does not exist in the range $B$2:$B$31.
You can wrap this formula around an IF Function to output a specific result. For example, if we want to add a “Does not exist” text for names that are not in the list, we can use the following formula:
=IF(COUNTIF($B$2:$B$31, Name)>0, “Exists”, “Does Not Exist”)
COUNTIF Value Exists in a Range Google Sheets
We use the same formula structure in Google Sheets:
=IF(COUNTIF(Range, Criteria)>0, “Exists”, “Does Not Exist”)
Skip to content
-
Check Also Extract Substring Between Parenthesis In Excel
-
Check Also Count Number Of Users Who Are Active In An Excel Workbook
-
Check Also VBA To Open Latest Excel Workbook
-
Check Also Print Cell Height And Cell Width Of A Cell In Excel
-
Check Also Delete Non Numeric Values From Numeric Field In Excel
-
Check Also Create Rows From Column In Excel
-
Check Also Sum Numbers Separated By Symbol In Excel
-
Check Also Sort Comma Separated Values Within A Cell In Excel
In this post we will see how to check if all the cells in a range have values in excel.
The range in excel could be of varied dimensions, and we will use formula to check about the existence of the values in a range.
When we say values, it could be anything like Text, Numeric, and Alphanumeric etc.
We will use COUTBLANK formula in excel to determine if all the cells in a range have values.
As you could see above we have arrangements of some data in a range and we want to check this range if all the cells in this are having values.
We will check both the scenario i.e. when the range has some blank values and when the range does not have any blank value.
Step 1
First We will see if all the cells in a range have values.
Enter the formula =NOT(NOT(COUNTBLANK(B4:E9))), in a cell as shown below.
B4:E9 is the range that we want to check.
COUNTBLANK will return us the number of cells that have blank values and NOT function is used just to get the result in TRUE/FALSE format here.
As you can see the cells in the range are completely filled and we do not have any blank values hence the formula has returned FALSE.
Step 2
Now we will delete some values in the range to check the formula.
As you could see the formula has returned TRUE that indicates that we have blank values in the range.
Additionally, if you want to calculate the number of blank values in a range, just remove the two NOT operator from the formula and you will get the count.
Hope this helped.
Random Posts