Beruflich Dokumente
Kultur Dokumente
In this article, I provide a formula for looking up a value and returning multiple occurrences of the same corresponding value in a list; for example, if in a two-column list, there appear multiple values of the name "Ashish" in the first column, the formula returns all of the corresponding values in the same row in the second column.
In this article
Look up one value and return one corresponding value Look up one value and return multiple corresponding values Identify row numbers Return corresponding values from column B Remove possible error values
The VLOOKUP function in cell B9 finds the first occurrence of the name "Ashish", and returns the corresponding value in the same row of the second column, which is 234.
Top of Page
Top of Page
Enter "Ashish" in cell A10. Then, enter the following array formula (CTRL+SHIFT+ENTER) in cell B10 to determine the row number of a corresponding value:
=SMALL(IF($A$1:$A$7=$A$10,ROW($A$1:$A$7)),ROW(1:1))
When you enter or fill this formula in subsequent cells, the formula returns the row numbers for each subsequent corresponding value, in this case, 4 and 7.
Top of Page
The first corresponding value is 234, the value that corresponds to the first occurrence of the name "Ashish". When you enter or fill this formula in subsequent cells, the formula returns the subsequent corresponding values of 534 and 834.
Top of Page
http://office.microsoft.com/en-in/excel-help/how-to-look-up-a-value-in-a-list-andreturn-multiple-corresponding-values-HA001226038.aspx
There are two worksheets, one containing Form data for a mail merge, and one containing Parcel data, some of which is to be included in the mail merge. The Form worksheet includes a row for each landowner who is to receive a letter. One of the columns in the spreadsheet is an ID for each landowner. The Parcel worksheet contains data about land parcels owned by the landowners in the Form worksheet. The mail merge will generate a letter to all land owners. That letter should include details of all of the land parcels owned by that individual land owner. In this lesson I'm going to focus on how to include that land parcel information in the mail merge, but I'm not going to discuss how to set up the mail merge with Microsoft Word.
As you can see, John Smith (ID H240) appears three times. We want to include a list of the crops John grows in our mail merge letter. If you've used a VLOOKUP function before, you'll know that we can use it to find the first crop in the list, but not the second or third.
o o o o o o o o
Note that you don't type these braces as part of the formula. You have to press Ctrl+Shift+Enter key when entering the formula to tell Excel it is an array formula, after which the { } will automatically appear. If you don't, our formula will return a #VALUE error. If you're using Excel for Mac, you'll need to press CMD+Enter instead. The SMALL function has the syntax SMALL(array,k). It looks up a list and finds the k'th smallest value in the array. If k = 1 it will find the smallest. If k=2 it will find the second smallest value, and so on. The second instance of the ROW function is used to find k in our formula. In this example, ROW will return the row number of row 1, which is ... 1. The IF function looks to see if the value in A10 is in the list. In our example, A10 is where we'll enter H240 as our lookup value. Note that the IF function will only return a value if our number is in the list. If not, it will return a null value, which will cause the SMALL function to generate an error. We'll look at how to hide that error later. The ROW function is used twice: If the IF function finds our value in the list, the ROW function returns the row number in which it was found. Note that it returns the row number of the worksheet, not the row number inside our table. This will be important later. As noted above, the ROW function is also used in our formula to return k. The screenshot below shows this formula in action:
In the screenshot above, I've entered h240 into A9 (you'll note that our formula isn't case sensitive). I've then entered the formula above into A11 as an array formula (don't forget that part!). It has returned 2, which is the row number for the first instance of H240 in the list. After that, I've copied and pasted the formula into rows A12 to A13. The formula has automatically picked up the correct row numbers, and generated an error when it couldn't find a fourth value. However, there has been some magic under the hood that you can't see here. When I copied and pasted the formula into the additional rows, the array formula changed. Here are the formulas in each cell:
{=SMALL(IF($A$2:$A$6=$A$9,ROW($A$2:$A$6)),ROW(1:1))} {=SMALL(IF($A$2:$A$6=$A$9,ROW($A$2:$A$6)),ROW(2:2))} {=SMALL(IF($A$2:$A$6=$A$9,ROW($A$2:$A$6)),ROW(3:3))} {=SMALL(IF($A$2:$A$6=$A$9,ROW($A$2:$A$6)),ROW(4:4))} Note how the ROW parameters in each formula are different: 1:1, 2:2, 3:3, 4:4. This is telling the SMALL function to find the 1st, 2nd, 3rd and 4th values in the list that match our lookup value. As I said, you don't need to edit the formula yourself - it updates itself when you copy and paste it.
The INDEX function looks in our table ($A$2:$B$7) It then uses the SMALL function to find which row to look in and then subtracts 1 from what SMALL tells us. Remember how the ROW function returns the row in the worksheet where our value was found? The INDEX function considers the first row of our table as row 1. Because our table data starts in row 2, we need to subtract 1 from the ROW value to get the correct row inside the table. If you're applying this solution to your own spreadsheet, you may need to adjust this value to take account of where your data table is located. The INDEX function then looks in column 3, which is where the crop data is found. Here's how our spreadsheet looks now.
The IF function tests to see if our formula generates an error. It does this by using the ISERROR function. If the ISERROR function is true (i.e. our formula generates an error) then the IF function returns "", which means the cell containing our formula will appear to be blank. If the ISRROR function is not true, then our formula works OK, and the IF function will use it to return the correct value. There's not much to see when we use this version of the formula, but here is what our spreadsheet looks like now:
And with that, we're finished. If you have any questions about this solution, please let us know in the comments! * This lesson was inspired by a post by Ashish Mathur for Excel 2003. You can read that post here. The instigation for this lesson came from a question from one of our readers on the original lesson on how to use the INDEX function.
Worked examples
Worked example file with a worksheet for each step in this lesson
Similar lessons
How to use the INDEX function to find data in an Excel table Learn to use the VLOOKUP function in Excel Use the MATCH function in Excel to find the position of a value in a list
Email Address * First Name * Subjects I'm interested in I want to learn more about: Excel Microsoft Word Google Analytics
Sign me up!
71 reddit1
10 googleplus67
I cannot figure a way to add a function to my spreadsheet - essentially what I want to happen is that when a person enters a year in cell c12, the value of cell c14 changes to the dollar amount of the package for that year - which I have in a table on the same sheet. I tried to get this to work with vlookup but have had no joy. I want to set the sheet up to automatically calculate a range of things with minimal input from users (and decreased errors as a result). If they know the year then I would rather have the sheet automatically populate with the approprate dollar value (which my team updates regularly based on indexation and cost changes). Any advice would be much appreciated! Cheers Michael Year Average cost 2013/14 $34,969 2014/15 $36,354 2015/16 $37,793 2016/17 $39,290 2017/18 $40,846 2018/19 $42,464 2019/20 $44,145 2020/21 $45,894 2021/22 $47,711 2022/23 $49,601 2023/24 $51,565
reply
Hi Michael I recreated your spreadsheet and verified that VLOOKUP will work in the scenario you've described. I don't see anything in that would require you use the INDEX function in the way it's used in this lesson.
The only potential problem I can see is if you want someone to type a year, e.g. 2020, rather than the range shown in your table above, either 2019/20 or 2020/21. In that case, this scenario won't work because VLOOKUP is looking for a match between what is typed in C14 and the values in the first column of your table. A value like 2020/21 is treated as a text value by Excel, so the text you type into C14 must match that text value. If you want someone to be able to type 2012 and have the formula return the correct result, you'll need to respecify the data table so the first column matches the potential values the users might type, i.e. 2013, 2014, 2015 etc. If you're unable/unwilling to respecify the values in the table, you could respecify the lookup value. The following formula shows a calculation that will take a year, e.g. 2013, and convert it into a text value (2013/14) so that it can be used in your VLOOKUP function. =C12&"/"&C12-1999 What it does is take the value in C12 and creates a text value by concatenating additional characters, starting with a / symbol, followed by another number. That number is the value in C12 (e.g. 2013) less 1999 (which gives us 14). So the result would be 2013/14, which is a text value. If you use this as the lookup value in VLOOKUP, it should return the result you want. I hope this helps! Regards David
reply
Hi, Thank you ever so much for the above - very helpful! I was just wondering if you might be able to help me expand the formula somewhat? I am interested in combining this with another IF and checking against an additional column e.g. if column A = M AND column B = Y then use INDEX to find the different values e.g. the first
instance of Y=Z, the second instance of Y=Z, the first instance of Y=T, the second instance of Y=T, the third instance of Y=T etc For reference, within this worksheet: Column A contains my references (the Ms mentioned above) and row 3 contains the numbers 1, 2, 3 etc. for the ROW(1:1) part e.g. first, second, third instance (I am dragging my formula horizontally rather than vertically as in your example above). Row 2 contains the Y criteria. In the other worksheet (containing the data I want to search through): Column_A is the column containing the Column A values from the previous sheet (the Ms) and Column_B contains the second search criteria. Search_Area is the full table. Header_Row is the header row and X and Y are some of the column labels. My original formula is: =IF(ISERROR(INDEX(Search_Area,SMALL(IF(ISNUMBER(SEARCH($A6, Column_A)),ROW(Column_A)),ROW(INDIRECT(B$3&":"&B$3))),MATCH("X", Header_Row,0))),"",INDEX(Search_Area,SMALL(IF(ISNUMBER(SEARCH($A6,Column_A)),RO W(Column_A)),ROW(INDIRECT(B$3&":"&B$3))),MATCH("X",Header_Row,0))) Ive expanded it to: =IF(ISERROR(INDEX(Search_Area,SMALL(IF(ISNUMBER(SEARCH($A6,Column_A)),ROW(Co lumn_A)),ROW(INDIRECT(P$3&":"&P$3))),MATCH("X",Header_Row,0))),"",IF(INDEX(Search_A rea,SMALL(IF(ISNUMBER(SEARCH($A6,Column_A)),ROW(Column_A)),ROW(INDIRECT(P$3 &":"&P$3))),MATCH("Y",Header_Row,0))=P$2,INDEX(Search_Area,SMALL(IF(ISNUMBER(SEA RCH($A6,Column_A)),ROW(Column_A)),ROW(INDIRECT(P$3&":"&P$3))),MATCH("X",Header_ Row,0)),"")) But it only works if the first value is Y=P2 which it isnt always! Is there a way to achieve this without splitting out all of the data into separate worksheets? Many thanks!
reply
hello i have the following row that includes 9 names (per working day). i can't know the names in
advance, and there might be the same guy appearing twice. below that row i have another one with the kilometers each guy drove. for example: Nick | Henk | Sidney | Nick | Roberth | Mark (so as you can see Nick is there twice, becasue he worked 2 days in that week). 100 | 210 | 150 | 190 | 45 | 76 i total, i will have 52 rows with names and 52 rows with KM, to cover the whole year... i want to have a side table to show me how mny KM each guy did on every week. so in the above example i'd like to have this: week 1 - Nick | Henk | Sidney | Nick | Roberth | Mark KM - 290 | 210 | 150 | 190 | 45 | 76 so as you can see, Nick's result was 290 (100+190) becasue he worked twice. i thought your trick with the INDEX and ROW was almost what i need, but i think i have to find the occurences of "NICK" looking DOWN, right?.. please help!... :( thanks! Ran
reply
Hi Ran It looks like you can do what you need with a simple SUMIF. People tend to think of SUMIF as being used for adding up data in columns, but it works just as well to add up data in rows provided you set it up correctly. Let's work with this example from the spreadsheet you provided. Here's the source data:
Here's where you want to calculate the results. The table starts in M13 with Amir's name (it's a little confusing, but the 18 in this picture refers to the Round from the picture above, not the row number in Excel):
The formula in round 18 for Amir is this: =SUMIF($C2:$K2,M$13,$C4:$K4) This formula looks in the cells from C2:K2 (the names in the table) and matches them with the value in M13 (Amir). If there is a match, it adds in the calue from the appropriate cell in the range C4:K4 (kilometers driven by that person). I've written this formula using a mixture of absolute and relative references so that you can copy and paste it from Amir to Yaron without changing it. However, the layout of your spreadsheet means that you can't just copy the same formula down to Round 19 without adjustment. Here's how the formula in Round 19 would need to look: =SUMIF($C5:$K5,M$13,$C7:$K7) As you can see, I've had to adjust the range references (e.g. $C2:$K2 became $C5:$K5), but not the reference to Amir's name (M$13). I hope this helps. Let me know if you still have any questions. You can read more about the SUMIFS function in this lesson. Regards David
reply
THANK YOU!
Submitted by Ran on Mon, 01/06/2014 - 12:21
71 reddit1 10 googleplus67 0
indeed, you are right! i guess i was complicating things unnecessarily... talking about this same spreadsheet, i have another question if you don't mind, in related to using of "IF"... in the attached file, i added another list. i want to see which operator worked at the following stadiums (Groningen, Roda JC, Cambuur). so i used this formula to search within the data of round 18: =IFERROR(INDEX(C2:K2,MATCH($N$2,C3:K3,0)),"") so N2 = Groningen in that case. now, if i want to auto copy this to all the way to the bottom, to cover rounds 19,20,21, etc etc, i can't use the drag method (from the corner of the cell), because it will increment the C2:K2 to be C3:K3. while i actually need it to be C5:K5... (this is where the data of round 19 is). so me question is: 1- how can i tell Excel to auto-increment by 3 numbers? so to jump from C2 to C5 to C8 etc etc? 2- if the above question is not possible,how can i add another "MATCH" parameter to also check the round number? for example: Match N2 (Groningen), but also match the round number (for example M6, M7 etc etc)?... i hope i explained my self correctly... many thanks for helping so far! Ran
reply
Almost there!
Submitted by alex parra on Mon, 01/13/2014 - 22:58
71 reddit1 10 googleplus67 0
Hello! I have your website to be of the utmost help. I appreciate the time you put into it, so thank you for that. I am writing as I'm pulling my hair out trying to figure out my work. I have two tables, one on sheet1 and the other on sheet2. They are setup in identical position, and their headers are identical. What I am looking to do is:
1. find where in the first table a variable occurs (say variable a1). 2. Count the instances of each unique variable. (I've accomplished this with copy and paste from pivot tables) 3. if variable a1 occurs three different instances in the first table, I would like to extract the corresponding data from table 2, that is in the exact same row/column as variable a1 - table2 holds an index of sorts. here would be an example (aside from the file I uploaded): table 1 header1 header2 header3 row1 a1 a2 a3 row2 a2 b1 a1 table2 header1 header2 header3 row1 1 2 3 row2 4 5 6 My goal is to output this: variable occurance index1 index2 a1 2 1 6 a2 1 2... any input would be greatly appreciated! I tried to capture the row and column of each variable, however the COLUMN function isn't behaving the same as the ROW function. I keep getting returned the COLUMN for the first occurance of the variable.