Excel look up value in array, return next value - excel

I would like to look up a value in a range and return the value in the next row, but can't quite figure out how to do this. I especially would like to do this with formulas rather than VBA, and preferably with built-in formulas than custom (VBA) formulas, due to macro security issues.
I'm using Excel 2010. My workbook has two worksheets, "assessment" and "lookup". In lookup, I have lookup tables.
"lookup" looks something like:
Column A Column B Column C
1 Sales Engineering Manufacturing
2 Alice Bobbie Charlie
3 Dawn Edgar Frank
4 George Holly Isabel
In "assessment," I have some some drop downs from which users select one name from each column in "lookup." Based on some other criteria, I then rank these and create a new, sorted list (using INDEX() and MATCH()) that produce the selected name and corresponding column name a new sort order
Column A Column B
10 Engineering Edgar
11 Sales Alice
What I'd like is to return the name from the next row.
Column C
10 Holly
11 Dawn
But I'm having real trouble figuring out how to get there.

Assuming lookups is located at B2:D5 (change as required) and the result data is at F2:H3 (change as required) enter this formula in cell H2 then copy down.
=INDEX(
INDEX($B$2:$D$5,0,MATCH($F2,$B$2:$D$2,0)),
1+MATCH($G2,
INDEX($B$2:$D$5,0,MATCH($F2,$B$2:$D$2,0)),0))

Related

How to use VLOOKUP function in MS Excel

I am very very new to Excel
I have two sheets
Sheet 1
Country PMU Cluster
A Asia Mercury
B Australia Venus
C North America Jupiter
All the countries and continents are unique here
In sheet 2
I have
CountryCode Country PMU Cluster
123 A
234 A
453 B
235 C
1 country can have multiple codes
I have to take the PMU and Cluster and merge it with Sheet 2 , sheet 2 will have an additional column of Country Code.
Any help is very much apprciated.
Replacing my answer per your edits.
I'm just doing this on a single sheet but you can easily adapt by pointing to your other sheet for your lookup array.
Here is the formula for cell G2:
==VLOOKUP($F2,$A:$C,2,FALSE)
Here is the formula for cell H2:
=VLOOKUP($F2,$A:$C,3,FALSE)
Drag your formulas down and you're done. Vlookup formulas are very useful I recommend looking up how they work as someone else could better explain than I. Basically, you are looking up a value (column F) in an array (columns A,B,C) and returning a column index (B = 2, C = 3, etc) for a match. Lastly, you are looking for an approximate (TRUE) or exact (FALSE) match. Almost always use FALSE.
Also, look up cell references and how to lock them (ie, how $ signs rules vary). That way you can easily drag formulas across and keep your lookup value and array the same.

Automatically working out the average of filtered results

I have a spreadsheet where column P has a score between 1-6
The cell O4 has the following formula: =AVERAGEIFS(P8:P5000,P8:P5000,"<>6",P8:P5000,"<>0")
This formula searches for the average of the score in column P excluding 6, blanks and 0
Column O has staff names e.g John, Mark, Tim.......
What i want to do is for Cell O4 to automatically calculate the average of the figures shown in column P after i have used the filter function to show only results of a selected staff member.
I was hoping excel might be able to do this automatically however cell O4 appears to still be showing the average of the whole column P regardless of whether i have filtered or not.
I was given the formula below on another forum but it seems to be giving slightly wrong results albeit only by a small amount but i need to have the results exact if possible. Any help appreciated.
=SUMPRODUCT(1-ISNUMBER(MATCH(P8:P100,{0,6},0)),SUBTOTAL(9,OFFSET(P8,ROW(P8:P100)-ROW(P8),0,1)))/SUMPRODUCT(1-ISNUMBER(MATCH(P8:P100,{0,6},0)),SUBTOTAL(2,OFFSET(P8,ROW(P8:P100)-ROW(P8),0,1)))
Maybe
{=AVERAGE(IF((P8:P5000<>6)*(P8:P5000<>0)*SUBTOTAL(103,INDIRECT("O"&ROW(8:5000))),P8:P5000))}
will do what you want. Assuming the Filter is on column O.
The 103 in SUBTOTAL will also exclude if rows are manually hidden. If this ist unwanted and it should only exclude hidden rows, if filtered, then use 3 instead.
This is an array formula. Input it into the cell without the curly brackets and then press [Ctrl]+[Shift]+[Enter] to create the array formula.
I would create a separate table in a new sheet with all unique staff members and then perform the calculation. This way, you can quickly compare values for all staff just by scanning the table instead of having to constantly update the filter to see the values for potentially dozens or hundreds of staff. You would add the staff name range and criteria to your AVERAGEIFS formula.
For your example:
Sheet 2
A B
--- ---
1 | Staff Average
2 | Bob =AVERAGEIFS(Sheet1!$P$8:$P$5000,Sheet1!$O$8:$O$5000,A2,Sheet1!$P$8:$P$5000,"<>6",Sheet1!$P$8:$P$5000,"<>0")
3 | Mary =AVERAGEIFS(Sheet1!$P$8:$P$5000,Sheet1!$O$8:$O$5000,A3,Sheet1!$P$8:$P$5000,"<>6",Sheet1!$P$8:$P$5000,"<>0")
4 | Joe =AVERAGEIFS(Sheet1!$P$8:$P$5000,Sheet1!$O$8:$O$5000,A4,Sheet1!$P$8:$P$5000,"<>6",Sheet1!$P$8:$P$5000,"<>0")

How can I remove non-matching values in two different columns and sort in Excel?

I have several columns of data in my Excel spreadsheet.
Originally, I had two different spreadsheets, as they were generated from reports in a software application.
One of the spreadsheets contains the names of individuals who have had transactions with us in the past year. The other spreadsheet contains the names and the phone numbers. I copied and pasted the columns with the names and phone numbers into my spreadsheet with just the names of people who have purchased something from us in the past year.
My ultimate goal is to extract the names and phone numbers of only the names that have purchased something in the past year.
My column for the past year contains 1,002 names, while my master customer list (with phone numbers) contains over 20,000 individuals. I need the phone numbers of all of the individuals that have purchased something from us in the past year, but I don't want to have to manually go through 1,000 names (and, essentially, 20,000+ to find the match).
If I can achieve my goal without having to use VBA, that would be great. If this is the only route I can take, then I will go that route, but I would like to avoid coding if possible. (This is simply due to time constraints.)
The VLOOKUP function is likely the best solution for you. From the Excel documentation, it:
Looks for a value in the leftmost column of a table, and then returns
a value in the same row from a column you specify. By default, the
table must be sorted in an ascending order.
Note well the implication of that last sentence: the column you're searching in (leftmost column of the lookup table) must be sorted in ascending order for this function to produce the correct results.
Taking a simple example, let's say you have Sheet1 in your Excel workbook with the following information:
A B C
1 Name Transactions Phone
2 Sally 3
3 Alice 5
4 Joe 2
5 Jon 1
You need to add their phone numbers to this sheet, from another workbook. Let's say your phone number information in the other workbook looks like this:
A B
1 Name Phone
2 Alice 2222222
3 Bill 3333333
4 Bob 4444444
5 Jim 5555555
6 Joe 6666666
7 Sally 7777777
8 Sue 8888888
9 Tom 9999999
Take the following steps to add the phone numbers to Sheet1 in the first workbook:
Copy the phone information into a blank sheet in the first workbook. Let's call this Sheet2 for this example.
Make sure the phone information is sorted ascending by the Name column (A), because that's the leftmost column and thus the lookup column.
In cell C2 of Sheet1 (the empty phone cell for Sally), enter: =VLOOKUP(A2, Sheet2!A$2:B$9, 2,FALSE).
Drag-copy this formula down to the remaining cells in the Phone column.
Result:
A B C
1 Name Transactions Phone
2 Sally 3 7777777
3 Alice 5 2222222
4 Joe 2 6666666
5 Jon 1 #N/A
Notes:
The second parameter (Table_array - the lookup data range) should not include the column headings. As you can see, it's Sheet2!A$2:B$9 so it includes the information from rows 2 to 9 in columns A and B.
The last parameter (Range_lookup) should be set to FALSE so you don't pick up the information from the closest match. Note how Jon has no matching phone number record, so his Phone is set to "#N/A" - otherwise he would have been assigned Joe's phone number since that's closest match to Jon.
Parameter documentation:
Lookup_value is the value to be found in the first column of the table, and can be a value, a reference, or a text string.
Table_array is a table of text, numbers, or logical values, in which data is retrieved. Table_array can be a reference to a range or
a range name.
Col_index_num is the column number in Table_array from which the matching value should be returned. The first column of values in
the table is column 1.
Range_lookup is a logical value: to find the closest match in the first column (sorted in ascending order) = TRUE or omitted; find
an exact match = FALSE.

Formula: Count text instance within table range

I want to find the instance of a text within a set range.
The following formula will work in general and produce the following info:
=COUNTIFS($B$2:$B2;$B2)
Helper Name
1 Bob
2 Bob
1 John
2 John
3 John
However, with this formula within a Table and insert data into a new row, you get this at the second instance of John:
=COUNTIFS($B$2:$B6;$B5)
Help Name
1 Bob
2 Bob
1 John
3 John
3 John
While the second instance of John should be:
=COUNTIFS($B$2:$B5;$B5)
Since a table will automatically fill in the formula when adding another row, is there a different way to make this formula or an option to make this work?
Sadly, the following code won't work:
=COUNTIFS($B$2:$B&Row(B5);$B5)
Thanks for any support!
This is a known problem with tables, new rows and auto-filled formulas that use conventional cell references. If you maintain the table method of cell addressing, you can reshape the range parameter of COUNTIF with OFFSET and use a table cell reference for the adjoining cell in the Name column.
    
The formula in the first Helper column cell below the header is,
=COUNTIF(OFFSET([Name],0,0,ROW(1:1),1),[#Name])
OFFSET is another volatile function (like INDIRECT) that recalculates on any calculation cycle; not just ones where the values that affect its outcome change. If you have a large amount of data, calculation lag will quickly become annoying.
More on this at Use structured references in Excel table formulas

Excel match and index to select value with 2 column and 1 row criteria

I'm trying to write a formula that can return a cell value using INDEX and MATCH but I can't make it work. I have the following setup:
year person pet friend sale
1 jeff scout matt computer
1 carole riley tom mouse
2 jeff sadi trung computer
2 carole daisy ellen mouse
Say I have three cells:
year 2
col person
sale mouse
RESULT: carole [year = 2, sale = mouse, column value from 'person']
Is there a way I can use index and match to zero in on the specific cell? I will always have a year and sale provided. However, the column (person, pet, or friend) will change so I need to find the value in that particular column where the year and mouse match the cells.
Once I get a formula to work I'm going to write a more general function, but I need help getting the INDEX/MATCH combo to work properly.
You could use a combination of Index and sumProduct:
=INDEX(Table1[[person]:[friend]],SUMPRODUCT(--(Table1[year]=J1)*--(Table1[sale]=J2)*ROW(Table1[[#Data],[year]]))-1,MATCH(J3,{"person","pet","friend"},0))
This would work as i
n the following example:
So J1 contains the year to look up, J2 contains the Sale name, and J3 is the column you want to return a value from.
Another option would to add a concatenated column to your table the has the values of year and sale:
you would then change the formula to:
=INDEX(Table1[[person]:[friend]],MATCH(K1&K2,Table1[Year&Sale],0),MATCH(K3,{"person","pet","friend"},0))
slightly shorter and defiantly faster.
NOTE: This might not work with versions of excel below 2010, if you are running an older version I can supply a modified answer.

Resources