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.
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.
Содержание
- Use Excel built-in functions to find data in a table or a range of cells
- Summary
- Create the Sample Worksheet
- Term Definitions
- Functions
- LOOKUP()
- VLOOKUP()
- INDEX() and MATCH()
- OFFSET() and MATCH()
- Checking if a value exists anywhere in range in Excel
- 4 Answers 4
- Check IF a Value Exists in a Range
- Check for a Value in a Range
- How this Formula Works
- Check for a Value in a Range Partially
- How to Check If Value Is In List in Excel
- Check If Value In Range Using COUNTIF Function
- Excel Find Value is in Range Example
- How to check if a value is in Range with Wild Card Operators
- Find if a Value is in a List Using MATCH Function
Use Excel built-in functions to find data in a table or a range of cells
Summary
This step-by-step article describes how to find data in a table (or range of cells) by using various built-in functions in Microsoft Excel. You can use different formulas to get the same result.
Create the Sample Worksheet
This article uses a sample worksheet to illustrate Excel built-in functions. Consider the example of referencing a name from column A and returning the age of that person from column C. To create this worksheet, enter the following data into a blank Excel worksheet.
You will type the value that you want to find into cell E2. You can type the formula in any blank cell in the same worksheet.
Term Definitions
This article uses the following terms to describe the Excel built-in functions:
The whole lookup table
The value to be found in the first column of Table_Array.
Lookup_Array
-or-
Lookup_Vector
The range of cells that contains possible lookup values.
The column number in Table_Array the matching value should be returned for.
3 (third column in Table_Array)
Result_Array
-or-
Result_Vector
A range that contains only one row or column. It must be the same size as Lookup_Array or Lookup_Vector.
A logical value (TRUE or FALSE). If TRUE or omitted, an approximate match is returned. If FALSE, it will look for an exact match.
This is the reference from which you want to base the offset. Top_Cell must refer to a cell or range of adjacent cells. Otherwise, OFFSET returns the #VALUE! error value.
This is the number of columns, to the left or right, that you want the upper-left cell of the result to refer to. For example, «5» as the Offset_Col argument specifies that the upper-left cell in the reference is five columns to the right of reference. Offset_Col can be positive (which means to the right of the starting reference) or negative (which means to the left of the starting reference).
Functions
LOOKUP()
The LOOKUP function finds a value in a single row or column and matches it with a value in the same position in a different row or column.
The following is an example of LOOKUP formula syntax:
The following formula finds Mary’s age in the sample worksheet:
The formula uses the value «Mary» in cell E2 and finds «Mary» in the lookup vector (column A). The formula then matches the value in the same row in the result vector (column C). Because «Mary» is in row 4, LOOKUP returns the value from row 4 in column C (22).
NOTE: The LOOKUP function requires that the table be sorted.
For more information about the LOOKUP function, click the following article number to view the article in the Microsoft Knowledge Base:
VLOOKUP()
The VLOOKUP or Vertical Lookup function is used when data is listed in columns. This function searches for a value in the left-most column and matches it with data in a specified column in the same row. You can use VLOOKUP to find data in a sorted or unsorted table. The following example uses a table with unsorted data.
The following is an example of VLOOKUP formula syntax:
The following formula finds Mary’s age in the sample worksheet:
The formula uses the value «Mary» in cell E2 and finds «Mary» in the left-most column (column A). The formula then matches the value in the same row in Column_Index. This example uses «3» as the Column_Index (column C). Because «Mary» is in row 4, VLOOKUP returns the value from row 4 in column C (22).
For more information about the VLOOKUP function, click the following article number to view the article in the Microsoft Knowledge Base:
INDEX() and MATCH()
You can use the INDEX and MATCH functions together to get the same results as using LOOKUP or VLOOKUP.
The following is an example of the syntax that combines INDEX and MATCH to produce the same results as LOOKUP and VLOOKUP in the previous examples:
The following formula finds Mary’s age in the sample worksheet:
The formula uses the value «Mary» in cell E2 and finds «Mary» in column A. It then matches the value in the same row in column C. Because «Mary» is in row 4, the formula returns the value from row 4 in column C (22).
NOTE: If none of the cells in Lookup_Array match Lookup_Value («Mary»), this formula will return #N/A.
For more information about the INDEX function, click the following article number to view the article in the Microsoft Knowledge Base:
OFFSET() and MATCH()
You can use the OFFSET and MATCH functions together to produce the same results as the functions in the previous example.
The following is an example of syntax that combines OFFSET and MATCH to produce the same results as LOOKUP and VLOOKUP:
This formula finds Mary’s age in the sample worksheet:
The formula uses the value «Mary» in cell E2 and finds «Mary» in column A. The formula then matches the value in the same row but two columns to the right (column C). Because «Mary» is in column A, the formula returns the value in row 4 in column C (22).
For more information about the OFFSET function, click the following article number to view the article in the Microsoft Knowledge Base:
Источник
Checking if a value exists anywhere in range in Excel
I want to check if the value of the cell A1 exist anywhere from sheet2!$A$2:$z$50.
IF the value exist then return the value of the 1st Row at the column where the match was found.
but this functions are limited to check if match at a single row / column.
I was hoping for something like =IF(A1,sheet2!$A$2:$Z$50,x1,FALSE) where x = the column where the match was found.
Is there something like that?
4 Answers 4
An array formula like this would work
Press Shift Ctrl Enter together
Say Sheet2 is like:
We want a formula on Sheet1 that will return the value in the header row if that column contains a value to be found. So if A1 contains Good Guy then the formula should return Victor Laszlo
Put the following UDF in a standard module:
User Defined Functions (UDFs) are very easy to install and use:
- ALT-F11 brings up the VBE window
- ALT-I ALT-M opens a fresh module
- paste the stuff in and close the VBE window
If you save the workbook, the UDF will be saved with it. If you are using a version of Excel later then 2003, you must save the file as .xlsm rather than .xlsx
To remove the UDF:
- bring up the VBE window as above
- clear the code out
- close the VBE window
To use the UDF from Excel:
=GetHeader(A1,Sheet2!A1:Z50)
To learn more about macros in general, see:
and for specifics on UDFs, see:
Macros must be enabled for this to work!
We give the UDF the entire range including the header row (although the header row is excluded from the search)
Источник
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.
Check for a Value in a Range
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.
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”.
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.
Источник
How to Check If Value Is In List 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
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:
You will have this as your output.
What If you remove “>0” from this if formula?
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.
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.
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:
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.
Источник
This post will guide you how to use VLOOKUP function to check if a value exists in a given range of cells in Excel. How to check if a specified value exists in a range and then return the value in the adjacent cell.
For example, you want to look up the text value “Excel” in the range B1:C7, and you found it in the Cell B4, then return the adjacent Sales value (C4) in the column C.
Name | Sales |
access | 45 |
word | 66 |
Excel | 34 |
ppt | 23 |
Word | 435 |
Word | 443 |
Table of Contents
- Check If a Value Exists in a Range
- Related Formulas
- Related Functions
Let’s write down the following Excel Formula based on the VLOOKUP function:
=VLOOKUP("Excel", B1:C7,2,TRUE)
Type this formula into the formula box in cell E1, then press Enter.
Let’s see how this formula works:
The VLOOKUP function can be used to check if a given values exists in a range of cell, then return the value in a specified column that is specified by the third argument in the function. So number 2 is the column number that we want to pick. The “Excel” is the value for that we want to lookup. B1:B7 is a range from which we want to lookup the value. The TRUE value indicates that we want to lookup an approximate match from range B1:C7.
- Lookup Entire Row using INDEX/MATCH
If you want to lookup entire row and then return all values of the matched row, you can use a combination of the INDEX function and the MATCH function to create a new excel array formula. - Extract the Entire Column of a Matched Value
If you want to lookup value in a range and then retrieve the entire row, you can use a combination of the INDEX function and the MATCH function to create a new excel formula..… - Lookup the Next Largest Value
If you want to get the next largest value in another column, you can use a combination of the INDEX function and the MATCH function to create an excel formula..
- Excel VLOOKUP function
The Excel VLOOKUP function lookup a value in the first column of the table and return the value in the same row based on index_num position.The syntax of the VLOOKUP function is as below:= VLOOKUP (lookup_value, table_array, column_index_num,[range_lookup])….
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”)
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
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.
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.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
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
6,0623 gold badges27 silver badges41 bronze badges
answered Jun 6, 2013 at 20:40
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)
answered Nov 10, 2014 at 22:57
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
1
For variety you can use MATCH, e.g.
=ISNUMBER(MATCH(D1,A3:A10,0))
answered May 29, 2013 at 23:28
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
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
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.
answered Aug 24, 2013 at 11:59
0
Array Formula version (enter with Ctrl + Shift + Enter):
=OR(A3:A10=D1)
answered Dec 8, 2016 at 12:38
SlaiSlai
1195 bronze badges
1