transcript

excelisfun - VLOOKUP To Get Complete Record: ROWS, COLUMNS or SEQUENCE Function? EMT 1532

Thumbnail of the video “excelisfun - VLOOKUP To Get Complete Record: ROWS, COLUMNS or SEQUENCE Function? EMT 1532”
Download Markdown
Community upload. AI output has not been independently verified.

Welcome to Excel Magic Trick number 1532. Today we need to talk about how to get VLOOKUP to return an entire record. Here is the lookup value we need to match, and then we want to pull the whole record down. We are going to see three options: the ROWS, COLUMNS, and SEQUENCE functions, all inside a VLOOKUP to help deliver the record.

If we go over to 1532, the question is whether we want to display the record horizontally or vertically. If we are displaying it vertically, the third argument in VLOOKUP, column index number, needs to be column number two for this ID in this cell. When we get down to the next cell, we need column number three, four, five, six, and so on. Similarly, up here we have the same problem: inside the formula, I need to generate the numbers two, three, four, five, and six.

When we use VLOOKUP and copy it horizontally across the columns or down across the rows, we have two different methods to generate those numbers internally. If we are copying across the columns, we use the COLUMNS function, the one with the S. COLUMNS is simple: if I highlight three cells across the range D to F, it counts the columns D, E, and F and returns a 3. So inside our array argument, I need an expandable range, so that in this cell I get the numbers two, three, four, and so on. We are sitting in cell C10, so I type $C$10:C, where the dollar sign locks the C column. When I copy the formula to the side, it remains on C, but the C without a dollar sign moves to D, then E, and so on. Control-Enter copies it to the side. If we pick any particular cell and hit F2, sure enough, the C is locked but the second C was allowed to move to E. Now we are counting columns C to E and get a 3. We really want two, three, four, and so on, so in the first cell I simply add one. Control-Enter copies it to the side, and that works in the third argument of VLOOKUP.

After the equal sign, before COLUMNS, comes VLOOKUP and a tab, then the lookup value, which is the ID, locked with the F4 key. Next comes the table array. This is an Excel table, so when I highlight the interior part, it puts in the correct table name. Then there is the COLUMNS formula element that generates the correct column numbers as we copy to the side. At the end comes the exact match argument, so we put FALSE or zero and close the parentheses. Control-Enter copies it to the side. Now we have to format this as currency. If I change this to a different ID, I get my record extracted.

We can use the same formula down here. Control-C, escape, and in edit mode Control-V. I cannot use COLUMNS here because that only works when copying to the side, so I double-click and use the ROWS function instead. I also no longer want to lock the C; I want to lock the 10. ROWS counts how many rows there are: from 10 to 10 is one plus one, which is two. That does not have a dollar sign, so when it gets to the next cell it counts from 10 to 11, which is two plus one. Control-Enter and copy it down, and I added some formatting. Now if I change the record, it does not matter whether it is horizontal or vertical: here we use COLUMNS, and here we use ROWS.

There is another way to do this, and it requires Office 365. In Office 365 there is a set of new dynamic array functions, and one of them, SEQUENCE, generates a sequence of numbers. This time we want the numbers to spill across the columns instead of down the rows, so I type a comma, then how many columns we are trying to fill, which is five, then the start number, which is two because that is the second column, and I leave out the step because the default is 1. I close the parentheses. These new dynamic arrays are completely different from anything we have had in Excel's 35-year history. When I hit Enter, it not only generates the numbers but automatically spills them into the correct number of cells. Then I apply number formatting, and we can clearly see two, three, four, five, and six, the perfect column numbers for VLOOKUP.

With dynamic arrays, if I click in the first cell, that is where the formula lives. Each subsequent cell is grayed out, so it does not live in that cell. You are still allowed to refer to it, but the formula does not actually live there. Here is where it gets even more amazing: SEQUENCE is spilling multiple items when I put it inside a VLOOKUP. There is the lookup value, and I do not have to hit F4 because the formula lives in this cell and just spills. Then comes the table, just as we did earlier, and the column index number. Because it is spilling, it instructs VLOOKUP to spill as well. Then comes zero and a close parenthesis. When I hit Enter, you will not believe that it retrieves the correct record in full. I could leave a 5 hard-coded in, but because that number actually comes from the count of these columns, I put in COLUMNS all the way from C3 to G3. COLUMNS delivers a 5, and when I hit Enter, that is totally amazing.

We can use this same formula and change just a few things. Copy, escape, and then in edit mode Control-V down here. I double-click and point the lookup value to that cell. The argument there tells SEQUENCE to spill across the columns, so I backspace and change it to spill down across the rows, which is what the start and step arguments are for. I do not want anything in the column argument, so I type a comma. That formula will spill vertically down the rows, and if I change the lookup value, it is totally amazing.

Let me know in the comments below: do you like this new SEQUENCE function, or do you prefer the good old standby we have had for decades, COLUMNS or ROWS? If you liked this video, be sure to click the thumbs up, leave a comment, and subscribe, because there are always many more videos to come from ExcelIsFun. We will see you in the next video.