Searching non-leftmost values with VLOOKUP-like function in Excel - excel

I have a question about excel function.
The question is:
I want to use VLOOKUP-like function, but VLOOKUP only search leftmost row.
Is there any function that searches non-leftmost row (you can select) and the behavior is almost same as VLOOKUP function?
If you don't understand, please see this picture.
I want to do like this in Excel.
Thank you for reading.

INDEX MATCH Combo
You can use combination of 2 functions:
INDEX function
The INDEX function returns a value or the reference to a value from within a table or range.
MATCH function
The MATCH function searches for a specified item in a range of cells, and then returns the relative position of that item in the range. For example, if the range A1:A3 contains the values 5, 25, and 38, then the formula =MATCH(25,A1:A3,0) returns the number 2, because 25 is the second item in the range.
Example
=INDEX(Name_col, MATCH(Rank_input, Rank_col, 0)).
Equivalent, using your concrete data, assuming you have "Alex" in A3:
=INDEX($A$3:$A$7, MATCH(A10, $C$3:$C$7, 0))

Related

INDEX/MATCH with 4 columns

I have an Excel file with 2 sheets - one sheet contains my items, prices, codes, etc. and the other sheet is for cross-matching with competitors.
I've included an Excel file and image below.
I want to be able to generate my code automatically when manually entering any of my competitor's codes. I was able to do INDEX/MATCH but I was only able to match with one column (I'm assuming they're all in one sheet to make it easier). Here is my formula:
=INDEX(C:C,MATCH(K2,E:E,0)
So this is looking only in E:E, when I tried to enter a different column such as C:C or D:D it returns an error.
I tried to do the MATCH as C:G but it gave an error right away.
The reason why match gave you error is because it's looking for an array and you put in multiple columns.
There is definitely a more elegant way to do this but this is the first one that I came up with.
=IFERROR(INDEX(B:B,MATCH(K2,C:C,0)),IFERROR(INDEX(B:B,MATCH(K2,D:D,0)),IFERROR(INDEX(B:B,MATCH(K2,E:E,0)),IFERROR(INDEX(B:B,MATCH(K2,F:F,0)),IFERROR(INDEX(B:B,MATCH(K2,G:G,0)),"")))))
Index/Match Combination
Please try this formula:
{=INDEX($B$2:$B$5,MATCH(1,(K2=$C$2:$C$5)+(K2=$D$2:$D$5)+(K2=$E$2:$E$5)+(K2=$F$2:$F$5)+(K2=$G$2:$G$5),0))}
Instruction: Paste the formula {without the curly brackets} to the formula bar and hit CTRL+SHIFT+ENTER while the cell is still active. This will create an array formula. Hence, the curly brackets. Please take note though that manually entering the curly brackets will not work.
Description:
The INDEX function returns a value or the reference to a value from within a table or range.1
The MATCH function searches for a specified item in a range of cells, and then returns the relative position of that item in the range.2
Syntax:
The INDEX function has two forms—Array and Reference form. We're going use the Reference form in this case.
INDEX(reference, row_num, [column_num], [area_num])1
MATCH(lookup_value, lookup_array, [match_type])2
Explanation:
To simplify, we're going to use this form:
INDEX(reference, MATCH(lookup_value, lookup_array, [match_type]))
The INDEX function returns a value from the reference My code column (B1:B5) based on the row_num argument, which serves as an index number to point to the right cell, and we're going to do that by substituting row_num with MATCH function.
MATCH function, on the other hand, returns the relative position of a value in competitorn column that matches the value in individual cells of the competitor code column.
To make it work with multiple lookup range, we're going to create arrays of boolean values (TRUE/FALSE, aka logical values) by comparing values from individual cells in competitor code column with values in individual competitorn columns. Now, we convert these boolean values into numerical values by performing a mathematical operation that does not alter its implied value (i.e. TRUE=1, FALSE=0). We're going to add these values directly to make it simple. The resulting array have four index with two possible values: 1 or 0. Since each item in MATCH's lookup_array is unique, then there can be only one TRUE or 1. The rest are FALSE or 0's. So, with that knowledge, we're going to use it as our lookup_value.
Let's dissect the formula:
=INDEX(B2:B5,MATCH(1,(K2=C2:C5)+(K2=D2:D5)+(K2=E2:E5)+(K2=F2:F5)+(K2=G2:G5),0))
My code 2 = INDEX({"My code 1";"My code 2";"My code 3";"My code 4"},MATCH)
My code 2 = INDEX({"My code 1";"My code 2";"My code 3";"My code 4"},(2))
2 = MATCH(1,(K2=C2:C5)+(K2=D2:D5)+(K2=E2:E5)+(K2=F2:F5)+(K2=G2:G5),0)
2 =MATCH(1,
{FALSE;FALSE;FALSE;FALSE}+
{FALSE;FALSE;FALSE;FALSE}+
{FALSE;FALSE;FALSE;FALSE}+
{FALSE;FALSE;FALSE;FALSE}+
{FALSE;TRUE;FALSE;FALSE},0))
OR
=MATCH(1,
{0;0;0;0}+
{0;0;0;0}+
{0;0;0;0}+
{0;0;0;0}+
{0;1;0;0},0))
=========
{0;1;0;0},0))
2 = MATCH(1,{0;1;0;0},0))
I hope this answer is helpful.
References and links:
INDEX function
MATCH function
Create an array formula

How and why is ROW(A1) used in these nested INDEX, MATCH and SMALL function formulas

In the following nested functions formulas, I do not understand why ROW(A1) is used or why it even works. Please refer to the picture and the 2 nested function formulas below. These nested functions produce the Category and Time Spent data on the right side of the picture using the data on the left side. The formula in the 'H' column returns the category title/description and the formula in the 'I' column returns the total time spent. These are ordered from smallest to highest "Time Spent" values.
From the inner most function of the nest, the small function returns the ROW(A1)th smallest number in the array of total time spent cells. The match function, I believe, then returns the column letter of where that value was found. The index function then displays the value in the column value returned by the match function and in the row specified by the array of cells. When you copy this nested function into each successive row, it increments the "A1" to "A2", "A3" and so on.
I thought the ROW function just returned the row number of a referenced cell and if that reference is left out, it defaults to the cell address that contains the ROW function. So why does ROW(A1) work here to change to the next nth smallest number to be found by the SMALL function in each successful row and formula???
H3 =INDEX($B$3:$F$3,MATCH(SMALL($B$2:$F$2,ROW(A1)),$B$2:$F$2,0))
I3 =INDEX($B$2:$F$2,MATCH(SMALL($B$2:$F$2,ROW(A1)),$B$2:$F$2,0))
Thanks!
VH
It's simply referring to the position in the named array in the small function. You are indicating position 1, first smallest.
First, look at what the formula resolves to on its own:
=ROW(A1)
This becomes simply 1. When used in a formula intended to be 'dragged down', the relative reference on A1 means that A1 will become A2, A3, and so on. On the 4th time that this is used, it will be:
=ROW(A4)
This resolves to 4. This is a common method to 'iterate' the number in a formula (increase in value by 1, for each new time the formula is used). Then, look at the SMALL function:
=SMALL($B$2:$F$2,4)
This gives you the 4th smallest number in the checked portion of row 2. Because the $'s are present, these references do not change as the formula is dragged down.
It seems you understand the remainder of that formula, but as you can now see, the SMALL function now adequately finds the smallest number in row 2, then the 2nd smallest number, etc.

How to pass text as cell reference in excel?

I have a vlookup which gives an output Sheet2!A:B. I want to use this sheet reference as an argument in another Vlookup as:
Vlookup(something, Sheet2!A:B,something, something)
I want the second Vlookup to use that as a cell reference. How can I do this?
If the first VLOOKUP function is returning the literal string "Sheet2!A:B" then wrap it in the INDIRECT function to convert text that looks like a cell range reference into an operational cell range reference. Example:
=VLOOKUP(1, Sheet1!A:Z, 26, FALSE) ◄ returns the text string "Sheet2!A:B" (sans quotes)
=VLOOKUP(<something>, INDIRECT(VLOOKUP(1, Sheet1!A:Z, 26, FALSE)), 2, FALSE)
You can just cascade the Lookups In this example, the first look-up in cell B2 finds the name of a happy person in table C1:D5.
The second look-up uses the result of the first to find the happy person's score in C7:D11

How to make an IF statement remain true throughout an INDEX MATCH in Excel 2010+?

I am trying to use an INDEX MATCH to return the optimal choice from a list of items associated to values that change based on various criteria. My current sheet setup and formula is this:
A B C
Item1 Bad 27
Item2 Good 15
Item3 Good 27
Item4 Bad 44
Column A is a named range Item.
Column B is a named range ItemType.
Column C is a named range ItemValue
=INDEX(INDIRECT(SUBSTITUTE('Sheet'!B3," ","")),MATCH(MAX(IF(INDIRECT(SUBSTITUTE('Sheet'!B3," ","")&"Type")="Good",INDIRECT(SUBSTITUTE('Sheet'!B3," ","")&"Value"))),INDIRECT(SUBSTITUTE('Sheet'!B3," ","")&"Value"),0))
(entered as an array formula)
In its current iteration, this will return Item1. I would like it to return Item3.
In this example, 'Sheet'!B3 contains the category to search (in this example Item). I use a variety of named ranges based on the data in that cell and suffixes with the use of INDIRECT/SUBSTITUTE. My current formula finds the highest value that also is Good, but then returns the first value that matches it, regardless of it being Good or Bad. I have tried adding an additional IF statement at different points of the formula but the cell would either return FALSE or a formula syntax error. How can I maintain my ="Good" IF statement throughout the formula?
Thank you!
You will need to double up the Good condition. Once for determining the max number and then again with the max number to determine the Item.
This non-array equivalent is the syntax I favor over the array method.
=INDEX(INDIRECT(SUBSTITUTE('Sheet'!B3," ","")), MAX(INDEX(ROW(INDIRECT(SUBSTITUTE('Sheet'!B3," ","")))*(INDIRECT(SUBSTITUTE('Sheet'!B3," ","")&"Type")="Good")*(INDIRECT(SUBSTITUTE('Sheet'!B3," ","")&"Value")=MAX(INDEX(INDIRECT(SUBSTITUTE('Sheet'!B3," ","")&"Value")*(INDIRECT(SUBSTITUTE('Sheet'!B3," ","")&"Type")="Good"), , ))), , )))
This is your array method.
=INDEX(INDIRECT('Sheet'!B3), MATCH(MAX(IF(INDIRECT('Sheet'!B3&"Type")="Good",INDIRECT('Sheet'!B3&"Value"))), IF(INDIRECT('Sheet'!B3&"Type")="Good", INDIRECT('Sheet'!B3&"Value")), 0))
If the ___Type and ___Value are always in the same position relative to the primary, you might want to abandon the three named ranges and just use a single named range with OFFSET.
=INDEX(INDIRECT('Sheet'!B3), MATCH(MAX(IF(OFFSET(INDIRECT('Sheet'!B3), 0, 1)="Good",OFFSET(INDIRECT('Sheet'!B3), 0, 2))), IF(OFFSET(INDIRECT('Sheet'!B3), 0, 1)="Good", OFFSET(INDIRECT('Sheet'!B3), 0, 2)), 0))
The OFFSET function is considered a volatile function. These recalculate whenever anything in the workbook changes and should be avoided for that reason. However, you are already using the INDIRECT function and that is considered volatile as well.

Get column by finding value in the row

In Excel, I've looked into hlookup, vlookup, match and index but none of these functions do following:
I need to find a text value in A1:Z1 and get the column of it. For example, I found the value in F1, then I want a result F:F.
EDIT: This is the function I want it to be added to:
=COUNTIFS(Source!B:B;Result!C3;Source!AT:AT;Result!$D$2)
I need the Source!B:B and alternatively Source!AT:AT be a search function that looks for a specific value in my table row and column in different sheet (Source).
INDEX function can return a whole column, e.g. assuming you want to search for "x" in A1:Z1 try
=INDEX(A:Z;0;MATCH("x";A1:Z1;0))
Note: this doesn't return a text string like F:F, it returns a reference to the column in question which you would normally use within a function that expects a whole column reference, e.g. SUM, SUMIF, LOOKUP etc.
Edited: You can use the above in COUNTIFS function like this:
=COUNTIFS(INDEX(Source!A:Z;0;MATCH("x";Source!A1:Z1;0));Result!C3;Source!AT:AT;Result!$D$2)
That makes the first range dynamic (between columns A and Z - extend as required) based on where "x" is first found in Source!A1:Z1, e.g. if "x" is first found in J1 then COUNTIFS uses Source!J:J for the first range - you can do that for any of the ranges in COUNTIFS
You can use this (it will return E:E, which you could then use INDIRECT with to return a workable range). This uses "words" as the word to match and stop at the first match:
=SUBSTITUTE(
ADDRESS(1,MATCH("words",$A$1:$Z$1,0),4),"1",
":"&
SUBSTITUTE(ADDRESS(1,MATCH("words",$A$1:$Z$1,0),4),"1",""))
This works by using MATCH to find the position of the occurrence in your range (in this case, 5), and then using ADDRESS, with row_num = 1 and column_num = the result of the match. Using 4 for the abs_num argument ensures that the returned value will be without the $'s. You then substitute out the 1 in E1 with ":" and concatenate it with the same formula, giving you E:E as a string. You can then do look-ups based on that range (using INDIRECT), such as this:

Resources