Welcome to Excel magic trick number 1,253. Hey, if you want to download this workbook Excel magic trick, 1251 to 1,253 and follow along, click on the link below the video. Here's a great question, a common question that people have: Can I make VLOOKUP use column headers? And the answer is absolutely yes. So, let's see how to do this.
We have ID, last name, first name, email, phone. This is a table of data. We need to type an ID here and then get first, phone, and email. Now notice the first name would be in the third column, the phone would be in the fifth column, and the email would be in the fourth column. Now, it's no problem with VLOOKUP. You could type these column numbers in, but there's a much easier way. And it's dynamic. If the names here change or the names in the table change, the formula will instantly update.
Now, before I do anything, if I have my IDs here, I want to create a drop-down list with all of the IDs. So, I'm going to click in that cell, go up to Data, over to Data Tools, Data Validation, Data Validation. The default is Allow Any Value. But we don't want that. We want this amazing list. And in the Source, we simply say please only allow these values in the cell. That's the data validation. But there's the in-cell dropdown. Click OK. Now we can select any particular ID.
Now VLOOKUP. VLOOKUP equals V L. The V is for vertical. The lookup is for looking stuff up. I'm going to look up the ID. And since I'm copying the formula to the side, I'm going to hit the F4 key to lock it. The table VLOOKUP always needs the thing it's trying to find and match in the first column. And then all the rest of the columns are potentially items we want to go and get and bring back to the cell, comma, column index number. Now, for the time being, I'm just going to put a three here because that's what most people do. Comma, and this is exact match. We're looking up some ID up here. And this may not be sorted. So, we're going to say we can use FALSE or zero. Either one will work. Close parentheses.
I can already see that I forgot to lock this. Now, here's a good hint. If you forget to lock, if you were to hit the F4 key right now, it would lock just A5. So, here's a trick. You click on the screen tip, it highlights the whole range. And then when you hit F4, boom, it locks it. Now, we can Ctrl+Enter. And for this one cell, it'll work. When I copy this over, notice it's giving me Catherine because three is in each cell.
Now, instead of editing these and changing them, we're going to learn about a different lookup function that can look up first, phone, and email within only this range. And it will tell us the relative position. And that lookup function is MATCH. So, I'm going to have a lookup value of, oh, there's the column header that we need VLOOKUP to understand as number three. That's a relative cell reference, comma. But for MATCH, the lookup array is only the field names. And you have to include the first column too because that's one. But notice 1, 2, 3. First is the third item in this list. Now I'm going to hit F4 to lock it. Comma and zero for exact match. Close parentheses. Ctrl+Enter. And drag it over to the side. And sure enough, it got the relative position of each one of those, which VLOOKUP will understand perfectly as a column index number.
Now, I'm going to copy the MATCH in edit mode. Ctrl+C, Escape, click back in the cell, F2, highlight the three, and Ctrl+V. There it is: the column index number is MATCH. But remember, MATCH is just delivering one of these numbers, which the column index can understand perfectly. Ctrl+Enter. Copy it over to the side. That is absolutely amazing.
Now if I change this to last, I haven't hit Enter yet, but watch, the MATCH will update. And of course, so will VLOOKUP. Enter. That is beautiful. So yes, we can make lookup use column headers. And the way we do it is column index number. Instead of typing it in, you use MATCH to look up the actual column or field names from the original data set. All right, we'll see you next video.
