In this video we need to know if each item from list 2 is in list 1 over here, and we need to do it with the formula. Anytime you're comparing two lists, there are two questions you can ask. The first question is: is this item over in this list? The answer is true if it is, and false if it is not. The second question you can ask is: is this item not over in this list? The answer is true if it's not, and false if it is.
We'll start with the first question: is Produce Fast and Fresh over in this list? Well, if we were doing it manually, we would see it's in the second position. Is Healthy Garden over here? Well, as I look through it, it doesn't look like it's there, but I don't trust my eyes, so I want a formula. We start by using the lookup function MATCH. I'm going to say, hey, look up that item, as a relative cell reference, comma, the entire lookup array, which is the entire list. We need to lock it with the F4 key so that as we copy down, its location stays the same. Comma, and we're doing exact match because we want to search for exactly those characters, 0, close parentheses. Control Enter puts the formula in the cell and keeps the cell selected. We can already see that it worked, because it's telling us the item for this row is in the second position over here. If I double-click and send my formula down, Healthy Garden gets a #N/A for Produce, which means it's not in the list. Third position, 6, 16. Those are all over in this list.
Anytime you do a formula that compares two lists, MATCH will give you a number or an #N/A. If you are interested in knowing if this item is over in the list, then you care about numbers. If you want to know if it's not on the list, you care about the #N/A error. Since we care about whether it is in the list, we use ISNUMBER. MATCH goes inside the closed parentheses, then Control Enter, double-click, and send it down. Now we have our array of TRUEs and FALSEs. TRUE means that item is in both lists. Once you have the TRUEs and FALSEs, that's the base of any formula that compares two lists when you're interested in whether the item is in both lists. Once you have these truths and falses, you can sort, filter, or even build an array formula.
If you're interested in the question of whether the item is not in the list, like in this library database situation, here's a list of all the books, and we went out and did an inventory. I want to know whether this item here is not over in this list. That means the book has not been returned. We do the same MATCH base, asking whether this item is over in here. MATCH will return the relative position. That book was found in the 83rd position over here. Double-click and send it down. Oops, East of Eden has not been returned. Now I have the whole column highlighted with the active cell at the top. I hit the F2 key, and because we're interested in whether it is not over in that other list, we use ISNA, then close parentheses. To populate this formula all the way down, I use Control Enter.
In summary: for "is in list," use ISNUMBER and MATCH. For "not in list," use ISNA and MATCH.
Here's your bonus formula. We could use VLOOKUP, but look at this: we look the item up in the list, and this is one of those weird situations where the column index is one, which means it will actually return the text item to the cell. To check whether the item is in both lists, we take that text item and ask whether it is an error. If it is, that means not in both lists, so we wrap NOT around it.
I have a great playlist of videos with all sorts of different ways you can compare and merge two lists; check out that playlist. Also check out the next Excel Magic Trick, where we'll see how to extract the items that are not in the second list.
