For =match()
to work, the value of the cells you are referencing have to be exact. Also, the match function only provides the location of the queried term in the search array. So, if you do this right, it will return a value greater than 0, which we can use to our advantage. Your =if()
function requires a logical test to work; if match
returns a number, it means it has found a match in the master list. We can test that number in if
and see if it is greater than 0 (which it will be); you should get "y"
.
Try this: =if(match(c2,$e:$e,0)>0,"y","n")
Also, another problem could lie in different entries from cols C
to E
. Are you using names? If yes, this is a bad practice; there are too many variables you can mess up when entering text strings. Try using ID numbers instead of names. You can then use =VLOOKUP()
to directly reference and match your employee names to employee ID numbers. This will work in a Workbook across different sheets.
You could try to do string matching. But, I recommend you switch to ID numbers.
IF function
The IF function is one of the most popular functions in Excel, and it allows you to make logical comparisons between a value and what you expect.
So an IF statement can have two results. The first result is if your comparison is True, the second if your comparison is False.
For example, =IF(C2=”Yes”,1,2) says IF(C2 = Yes, then return a 1, otherwise return a 2).
Use the IF function, one of the logical functions, to return one value if a condition is true and another value if it’s false.
IF(logical_test, value_if_true, [value_if_false])
For example:
-
=IF(A2>B2,»Over Budget»,»OK»)
-
=IF(A2=B2,B4-A4,»»)
Argument name |
Description |
---|---|
logical_test (required) |
The condition you want to test. |
value_if_true (required) |
The value that you want returned if the result of logical_test is TRUE. |
value_if_false (optional) |
The value that you want returned if the result of logical_test is FALSE. |
Simple IF examples
-
=IF(C2=”Yes”,1,2)
In the above example, cell D2 says: IF(C2 = Yes, then return a 1, otherwise return a 2)
-
=IF(C2=1,”Yes”,”No”)
In this example, the formula in cell D2 says: IF(C2 = 1, then return Yes, otherwise return No)As you see, the IF function can be used to evaluate both text and values. It can also be used to evaluate errors. You are not limited to only checking if one thing is equal to another and returning a single result, you can also use mathematical operators and perform additional calculations depending on your criteria. You can also nest multiple IF functions together in order to perform multiple comparisons.
-
=IF(C2>B2,”Over Budget”,”Within Budget”)
In the above example, the IF function in D2 is saying IF(C2 Is Greater Than B2, then return “Over Budget”, otherwise return “Within Budget”)
-
=IF(C2>B2,C2-B2,0)
In the above illustration, instead of returning a text result, we are going to return a mathematical calculation. So the formula in E2 is saying IF(Actual is Greater than Budgeted, then Subtract the Budgeted amount from the Actual amount, otherwise return nothing).
-
=IF(E7=”Yes”,F5*0.0825,0)
In this example, the formula in F7 is saying IF(E7 = “Yes”, then calculate the Total Amount in F5 * 8.25%, otherwise no Sales Tax is due so return 0)
Note: If you are going to use text in formulas, you need to wrap the text in quotes (e.g. “Text”). The only exception to that is using TRUE or FALSE, which Excel automatically understands.
Common problems
Problem |
What went wrong |
---|---|
0 (zero) in cell |
There was no argument for either value_if_true or value_if_False arguments. To see the right value returned, add argument text to the two arguments, or add TRUE or FALSE to the argument. |
#NAME? in cell |
This usually means that the formula is misspelled. |
Need more help?
You can always ask an expert in the Excel Tech Community or get support in the Answers community.
See Also
IF function — nested formulas and avoiding pitfalls
IFS function
Using IF with AND, OR and NOT functions
COUNTIF function
How to avoid broken formulas
Overview of formulas in Excel
Need more help?
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
Getting IF Function to Work for Partial Text Match
In the dataset below, we want to write a formula in column B that will search the text in column A. Our formula will search the column A text for the text sequence “AT” and if found display “AT” in column B.
It doesn’t matter where the letters “AT” occur in the column A text, we need to see “AT” in the adjacent cell of column B. If the letters “AT” do not occur in the column A text, the formula in column B should display nothing.
Searching for Text with the IF Function
Let’s begin by selecting cell B5 and entering the following IF formula.
=IF(A5="*AT*","AT","")
Notice the formula returns nothing, even though the text in cell A5 contains the letter sequence “AT”.
The reason it fails is that Excel doesn’t work well when using wildcards directly after an equals sign in a formula.
Any function that uses an equals sign in a logical test does not like to use wildcards in this manner.
“But what about the SUMIFS function?”, I hear you saying.
If you examine a SUMIFS function, the wildcards don’t come directly after the equals sign; they instead come after an argument. As an example:
=SUMIFS($C$4:$C$18,$A$4:$A$18,"*AT*")
The wildcard usage does not appear directly after an equals sign.
SEARCH Function to the Rescue
The first thing we need to understand is the syntax of the SEARCH function. The syntax is as follows:
SEARCH(find_text, within_text, [start_num])
- find_text – is a required argument that defines the text you are searching for.
- within_text – is a required argument that defines the text in which you want to search for the value defined in the find_text
- Start_num – is an option argument that defines the character number/position in the within_text argument you wish to start searching. If omitted, the default start character position is 1 (the first character on the left of the text.)
To see if the search function works properly on its own, lets perform a simple test with the following formula.
=SEARCH("AT",A5)
We are returned a character position which the letters “AT” were discovered by the SEARCH function. The first SEARCH found the letters “AT” beginning in the 1st character position of the text. The next discovery was in the 5th character position, and the last discovery was in the 4th character position.
The “#VALUE!” responses are the SEARCH function’s way of letting us know that the letters “AT” were not found in the search text.
We can use this new information to determine if the text “AT” exists in the companion text strings. If we see any number as a response, we know “AT” exists in the text string. If we receive an error response, we know the text “AT” does not exist in the text string.
NOTE: The SEARCH function is NOT case-sensitive. A search for the letters “AT” would find “AT”, “At”, “aT”, and “at”. If you wish to search for text and discriminate between different cases (case-sensitive), use the FIND function. The FIND function works the same as SEARCH, but with the added behavior of case-sensitivity.
Turning Numbers into Decisions
An interesting function in Excel is the ISNUMBER function. The purpose of the ISNUMBER function is to return “True” if something is a number and “False” if something is not a number. The syntax is as follows:
ISNUMBER(value)
- value – is a required argument that defines the data you are examining. The value can refer to a cell, a formula, or a name that refers to a cell, formula, or value.
Let’s add the ISNUMBER function to the logic of our previous SEARCH function.
=ISNUMBER(SEARCH("AT",A5))
Any cell that contained a numeric response is now reading “True” and any cell that contained an error is now reading “False”.
We are now able to use the ISNUMBER/SEARCH functions as our wildcard statement in the original IF function.
=IF(ISNUMBER(SEARCH("AT",A5)),"AT","")
This is a great way to perform logical tests in functions that do not allow for wildcards.
Let’s see another scenario
Suppose we want to search for two different sets of text (“AT” or “DE”) and return the word “Europe” if either of these text strings are discovered in the searched text. We will combine the original formula with an OR function to search for multiple text strings.
=IF(OR(ISNUMBER(SEARCH("AT",A5)),ISNUMBER(SEARCH("DE",A5))),
"Europe","")
Practice Workbook
Feel free to Download the Workbook HERE.
Published on: June 2, 2019
Last modified: March 29, 2023
Leila Gharani
I’m a 5x Microsoft MVP with over 15 years of experience implementing and professionals on Management Information Systems of different sizes and nature.
My background is Masters in Economics, Economist, Consultant, Oracle HFM Accounting Systems Expert, SAP BW Project Manager. My passion is teaching, experimenting and sharing. I am also addicted to learning and enjoy taking online courses on a variety of topics.
The logical IF statement in Excel is used for the recording of certain conditions. It compares the number and / or text, function, etc. of the formula when the values correspond to the set parameters, and then there is one record, when do not respond — another.
Logic functions — it is a very simple and effective tool that is often used in practice. Let us consider it in details by examples.
The syntax of the function «IF» with one condition
The operation syntax in Excel is the structure of the functions necessary for its operation data.
=IF(boolean;value_if_TRUE;value_if_FALSE)
Let us consider the function syntax:
- Boolean – what the operator checks (text or numeric data cell).
- Value_if_TRUE – what will appear in the cell when the text or numbers correspond to a predetermined condition (true).
- Value_if_FALSE – what appears in the box when the text or the number does not meet the predetermined condition (false).
Example:
Logical IF functions.
The operator checks the A1 cell and compares it to 20. This is a «Boolean». When the contents of the column is more than 20, there is a true legend «greater 20». In the other case it’s «less or equal 20».
Attention! The words in the formula need to be quoted. For Excel to understand that you want to display text values.
Here is one more example. To gain admission to the exam, a group of students must successfully pass a test. The results are listed in a table with columns: a list of students, a credit, an exam.
The statement IF should check not the digital data type but the text. Therefore, we prescribed in the formula В2= «done» We take the quotes for the program to recognize the text correctly.
The function IF in Excel with multiple conditions
Usually one condition for the logic function is not enough. If you need to consider several options for decision-making, spread operators’ IF into each other. Thus, we get several functions IF in Excel.
The syntax is as follows:
Here the operator checks the two parameters. If the first condition is true, the formula returns the first argument is the truth. False — the operator checks the second condition.
Examples of a few conditions of the function IF in Excel:
It’s a table for the analysis of the progress. The student received 5 points:
- А – excellent;
- В – above average or superior work;
- C – satisfactory;
- D – a passing grade;
- E – completely unsatisfactory.
IF statement checks two conditions: the equality of value in the cells.
In this example, we have added a third condition, which implies the presence of another report card and «twos». The principle of the operator is the same.
Enhanced functionality with the help of the operators «AND» and «OR»
When you need to check out a few of the true conditions you use the function И. The point is: IF A = 1 AND A = 2 THEN meaning в ELSE meaning с.
OR function checks the condition 1 or condition 2. As soon as at least one condition is true, the result is true. The point is: IF A = 1 OR A = 2 THEN value B ELSE value C.
Functions AND & OR can check up to 30 conditions.
An example of using the operator AND:
It’s the example of using the logical operator OR.
How to compare data in two tables
Users often need to compare the two spreadsheets in an Excel to match. Examples of the «life»: compare the prices of goods in different bringing, to compare balances (accounting reports) in a few months, the progress of pupils (students) of different classes, in different quarters, etc.
To compare the two tables in Excel, you can use the COUNTIFS statement. Consider the order of application functions.
For example, consider the two tables with the specifications of various food processors. We planned allocation of color differences. This problem in Excel solves the conditional formatting.
Baseline data (tables, which will work with):
Select the first table. Conditional Formatting — create a rule — use a formula to determine the formatted cells:
In the formula bar write: = COUNTIFS (comparable range; first cell of first table)=0. Comparing range is in the second table.
To drive the formula into the range, just select it first cell and the last. «= 0» means the search for the exact command (not approximate) values.
Choose the format and establish what changes in the cell formula in compliance. It’s better to do a color fill.
Select the second table. Conditional Formatting — create a rule — use the formula. Use the same operator (COUNTIFS). For the second table formula:
Download all examples in Excel
Now it is easy to compare the characteristics of the data in the table.