Lookup next column if lookup value begins with certain string - excel

I am trying to match a value in an array. If the lookup value begins with any value in the table then it will return the value in the next column. The problem is that each value in Column A is of different length.
Is it still possible to match it in Excel without using VBA?

Try looking up the "most demanding" string first (most characters) and if not found (ie an error), look up progressively shorter strings, eg:
=IFERROR(VLOOKUP(LEFT(D3,4),A:B,2,0),VLOOKUP(LEFT(D3,3),A:B,2,0))

Related

How to reverse Match for cell containing string Excel 2010

From column O I would like to lookup column A, starting from my current row, to find the first cell with a comma. Goal is to have the correct date in each row.
Table I'm working in https://i.imgur.com/BByfjzy.png
=MATCH("*"&","&"*",$A$1:INDIRECT("A" & ROW()),0)
If I could just run it backwards that be great but I'm not finding a way that works with wildcards or contains in excel 2010. My other thought was to make an a range based off position, invert it, find the index and do length - index but I'm not sure how I would go about that. I'm pretty new to excel so any help would be apricated.
=MAX(IF(ISNUMBER(FIND(",",A1:INDEX(A:A,ROW()))),ROW(A1:INDEX(A:A,ROW())),))
Instead of MATCH which looks from top to bottom and returns the first match, use MAX to return the max row number of the cell containing ,. You can use either FIND or SEARCH.
If you wrap it in INDEX you get your value:
=INDEX(A:A,MAX(IF(ISNUMBER(FIND(",",A1:INDEX(A:A,ROW()))),ROW(A1:INDEX(A:A,ROW())),)))
It might require to be entered with ctrl+shift+enter. I'm unable to test it in older Excel version.
Edit for further explanation of how it works:
A1:INDEX(A:A,ROW()) is to be read as cell A1 up to the current row in column A. So if you're at row # 10 it would equal A1:A10.
Wrapping that range in FIND returns the position of the character you try to find.
If given character is not found in the cell it returns error #N/A.
So if you have row 1 and 9 containing , in this case, it returns an array of numbers for the hits and errors for the non-hits, for instance {2,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,#N/A,6,#N/A}
Wrapping that in ISNUMBER changes the non errors to TRUE and the errors to FALSE.
IF takes that array and in case of TRUE (a number) it returns the row number (same indexed range is used).
Then MAX returns the largest row number of that array.
Instead of FIND you could also use SEARCH. FIND is case sensitive, and SEARCH isn't, further on they operate the same).

MATCH subtracting afterwards? MATCH (lookup;array;match_type) -1

The question: if MATCH uses (lookup;array;match type) why there is a -1 after?
I have an Excel sheet at work that uses match in a way I cannot figure out.
The original formula:
=IF(E2<>"";OFFSET('Sheet1'!$A$2;MATCH(E2;Streams;0)-1;0;COUNTIF(Streams;E2);1);ITID)
The break down for the MATCH's part is:
MATCH(E2;Streams;0)-1;
The lookup value "E2" contains selectable values from "Streams", which is a named list. This named list "Streams" contains non numeric values like:
LOG
PLTP
PTP
OTC
etc...
Just understood that Match gives back the number position of the result, not the result itself.

How can I get the location of a cell in Excel based on its value if it's not the first one in the column?

I know how to use index and match formulas to get the value or location of a matching cell. But what I don't know how to do is get that information when the cell I'm looking for isn't going to be the first match.
Take the image below for example. I want to get the location of the cell that says "Successful Deliveries". In this example there's a cell that matches that in rows 11 and 30. These locations can vary in the future so I need a formula that's smart enough to handle that.
How would I get the location of the second instance of "Successful Deliveries"? I figured I could use the "Combination 2 Stats" value from row 24 as a starting point.
I tried using this formula:
=MATCH("Successful Deliveries:",A24:A1000,0)
But it returns a row number of 7 which is just relative to the A24 cell I started my match at.
My end goal here is to get the value from the cell directly to the right of the second match of "Successful Deliveries".
In your formula, with no further intelligence, you can simply add 23 to adjust 7 to the result:
=MATCH("Successful Deliveries:",A24:A1000,0) + 23
You know that 23 is the number to add because you started your search on row 24.
The full answer is here:
https://exceljet.net/formula/get-nth-match-with-index-match
You use this formula:
=INDEX(B1:B100,SMALL(if(A1:A100 = "Successful Deliveries:",ROW(A1:A100) - ROW(INDEX(A1:A100,1,1))+1),2))
...where 2 is the instance you want.
Make sure to finish typing the formula by hitting ctrl-shift-enter. (You know you did this right because the formula gets curly brackets {})
HOW IT WORKS
Normally, we use INDEX / MATCH to find a value. The Index function gives you the nth value in a range, and the Match function determines which "n" is a match for our criteria.
Here we use INDEX the same way, but we need more intelligence to find that "n", since it's the second one that matches the criteria. That's where SMALL comes in. The Small function "gets the nth smallest value in an array". So we give Small the number of the desired instance (2 in this case) and we give it an array of blanks and the rows numbers of the rows we like.
We obtained the array of blanks and row numbers using the If function, asking it to check for our criterion (="Successful...") and making it return the row number where the criterion passes (=Row(A1:A100)). By using the If function as an array function (by giving it arrays and using ctrl-shift-enter) it can deliver a whole list of values.
Our final value is just one number because the Small function used the array from the IF to return just one thing: the second-smallest row we gave to it.

Excel: Compare list of strings with a column of partial strings,if match then return the partial string

I have a list of strings in Column A. I want to match the entries in column G (partial strings) with the strings in column A. If there is a match, I want to print out the partial string in Column B (output).
I have used the following formula -
=IF(SUMPRODUCT(--ISNUMBER(SEARCH(G:G,A1)))>0,"found","notfound")
to print out found or notfound string, but I am not able to print out the partial string value in column B.
Any help would be appreciated.
You can use INDEX with an AGGREGATE to return the row number:
=IFERROR(INDEX(G:G,AGGREGATE(15,6,ROW($G$2:$G$3)/(ISNUMBER(SEARCH($G$2:$G$3,A2))),1)),"")
Aggregate is an array type formula and as such the references needs to be constrained to the data set and not a full column reference.
Also the sub string must match fully in the larger string, in your example Please contact agent would not be found in Please contact the agent As the splits the string and will not match.
To make the formula more dynamic, so it does not need to be edited every time a sub-string is added or removed from the list and still maintain the smallest reference we can use another INDEX/MATCH to find the end of the list and set this as the end of the reference.
=IFERROR(INDEX(G:G,AGGREGATE(15,6,ROW($G$2:INDEX(G:G,MATCH("ZZZZ",G:G)))/(ISNUMBER(SEARCH($G$2:INDEX(G:G,MATCH("ZZZZ",G:G)),A2))),1)),"")

Return the index of the last column with a specific name in excel

I'm trying to create an excel register that counts the number of times someone has registered, and returns the date of the last time they turned up but am having trouble with this last step:
See this simplified setup:
To do this, I assume I need to find the index value of the column in which the name last appears, and the use it to return the date in the first row, the tricky part trying to get that index value.
I've tried to use lookup formulas and am pretty sure that an array formula is how this can be accomplished but am unsure how I can use them in this specific case.
Assuming you have Excel 2010 or later:
=INDEX($1:$1,AGGREGATE(14,6,COLUMN(A$2:D$8)/(A$2:D$8=O2),1))
Copy down as required.
The explanation is as follows:
The portion:
(A$2:D$8=O2)
simply returns an array of Boolean TRUE/FALSE values as to whether each of the cells within that range is equal to the entry in O2 or not, i.e. using your example:
{TRUE,FALSE,TRUE,FALSE;FALSE,FALSE,FALSE,FALSE;FALSE,TRUE,FALSE,FALSE;FALSE,FALSE,FALSE,TRUE;FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE}
The part:
COLUMN(A$2:D$8)
returns the column number for each column within the specified range, i.e.:
{1,2,3,4}
By reciprocating this array with that containing our conditional Boolean TRUE/FALSE returns, we produce an array whose only numerical entries correspond to columns in which our search string (i.e. "James") is located, since:
COLUMN(A$2:D$8)/(A$2:D$8=O2)
which is:
{1,2,3,4}/{TRUE,FALSE,TRUE,FALSE;FALSE,FALSE,FALSE,FALSE;FALSE,TRUE,FALSE,FALSE;FALSE,FALSE,FALSE,TRUE;FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE;FALSE,FALSE,FALSE,FALSE}
becomes:
{1,#DIV/0!,3,#DIV/0!;#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!;#DIV/0!,2,#DIV/0!,#DIV/0!;#DIV/0!,#DIV/0!,#DIV/0!,4;#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!;#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!;#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!}
by virtue of the fact that, when subjected to a suitable mathematical operation (of which division is one), Boolean TRUE/FALSE values are coerced into their numerical equivalents (TRUE=1, FALSE=0), meaning that, effectively, for any numerical value x:
x/TRUE ⇒ x/1 = x
and:
x/FALSE ⇒ x/0 = #DIV/0!
By setting AGGREGATE's first parameter to 14 (equivalent to the function LARGE) and its second to 6 (instructing it to ignore any errors in the array passed), we can extract the largest column index which meets our criterion, such that:
AGGREGATE(14,6,COLUMN(A$2:D$8)/(A$2:D$8=O2),1)
which is here:
AGGREGATE(14,6,{1,#DIV/0!,3,#DIV/0!;#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!;#DIV/0!,2,#DIV/0!,#DIV/0!;#DIV/0!,#DIV/0!,#DIV/0!,4;#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!;#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!;#DIV/0!,#DIV/0!,#DIV/0!,#DIV/0!},1)
returns 4.
All that is left is to pass this value to INDEX, such that:
INDEX($1:$1,AGGREGATE(14,6,COLUMN(A$2:D$8)/(A$2:D$8=O2),1))
which is:
INDEX($1:$1,4)
returns:
13/11/2015
as required.
Regards

Resources