Match lookup value lengths for match with beginning of lookup value - excel

In Excel 2013 I have two tables.
The first contains alpha numeric codes that vary in length.
Some examples from first table:
12345.12345
12346-12345
12AB1234
123.123
23456.123
A1234567.012
01234.12345
The second table contains alpha numeric codes I need to match with the beginning of the codes in the first table. Any numeric codes are currently stored as text.
Some examples from second table:
12345
12346
123
23456
A1234567
01234
How do I return a value from a different column in the second table containing any value? And for some context, the return column from the second table contains a description of for the codes.
I did not jet manage to find a solution using vlookup or match.
Also looked at using wildcards, but this only works one way, the wrong way.

The quickest solution, assuming you dont care about letters, is to use a LEFT(FIND( with substitution. If letters need to be excluded, then explanation will need to be provided how the format should be presented.
Solution: =IFERROR(LEFT(A2,FIND(".",SUBSTITUTE(A2,"-","."))-1),A2)
This formula will find the first "." or "-" and present all characters prior to. If none are found, then it will display the full ID.
If letters need to be removed as well, however, it should be noted that the use of some serious substitute nesting, or VBA script will be required.

A1 is the first cell in your column, in B1 write the following:
=LEFT(A1,MATCH(TRUE,ISERROR(VALUE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))),0)-1)
press Ctrl+Shift+Enter at the same time (Array Formula)
it will return the first numeric part of your Data
you can copy paste values in column C and compare with the second table
To have the result in Table1 directly in B1 use:
=IFERROR(INDEX(Sheet2!$A$1:$A$4,MATCH(VALUE(LEFT(A1,MATCH(TRUE,ISERROR(VALUE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))),0)-1)),Sheet2!$A$1:$A$4,0)),"")
press Ctrl+Shift+Enter at the same time (Array Formula)
It will return the corresponding number from Table2 (sheet2) if matched or "" empty if no match
Change A1:A4 to correspond all your Numbers in Table2 and keep the $ to fix the references when you drag down the formula

Related

Write data from a list if the adjacent cell contains certain string

I need to update hundreds of cells, and that would be trivial automating, but I am not being able to make it work.
I have a list like the following:
And, in a different tab, a list I have to populate with values above (in B) based on the appearance of the twitter handle in other column.
The names are within a long text string (all of them begin with #), and it is not possible to re-order the list based on those names. Also, there are more names than values, so some cells will remain blank.
Is there a way I can write a formula that writes the values of the first list into the second one if the name in column A in that row is contained within the adjacent string?
Thanks!
You can refer to this sample formula (Same sheet was used):
=arrayformula(if(C2:C<>"",iferror(vlookup(REGEXEXTRACT(C2:C,"\B\#\w+"),A2:B,2,false),""),""))
What it does?
Use array formula to loop column C values
Extract the twitter name (string that starts with #) using Regexextract()
Use the extracted #twittername as search key to get the connections value using vlookup()
Output:
Since we don't have access to the spreadsheet, I can't know for sure what the line-break character is within the Col-A cells of your second sheet. And using this line-break character is important, since Twitter handles may use some non-alphanumeric characters such as the underscore and others which are not included in such REGEX notation as \w. I'm assuming here that the line-break character is CHAR(10) from the ASCII chart.
I also don't know the name of your first sheet; so here, I've just written it as Sheet1. You'll need to replace that with your actual sheet name, remembering to place it in single quotes if it contains anything but alphanumeric characters (e.g., 'Data Sheet').
That said, delete everything from Col-B in your second sheet (including the header "Connections") and place the following formula in cell B1 of that second sheet):
=ArrayFormula({"Connections"; IF(A2:A="",, IFERROR(VLOOKUP(REGEXEXTRACT(SUBSTITUTE(A2:A,CHAR(10),"~"),"#[^~]+"),Sheet1!A:B,2,FALSE)))})

Match function in Excel returns N/A

I have the following 3 columns in my excel sheet. The dates in column A (DateTime) are in the same format as column N(DateTime2) :
Example of Excel matrix
The data are a lot, so I can't check it one by one. I tried to use match command in order to identify which date from column N(DateTime2) exist in column A(DateTime). I used the following command:
=MATCH(N2;$A$2:$A$5849;0)
I used autofill and as a result I got only first value as a number (which means that it exists), and the rest as N/A ..which is wrong. As you can see the value 1/1/16 3:00 exist in both columns.
I tried then to use the function VLOOKUP and I wrote the following command:
=VLOOKUP(N2;$A$2:$A$5849;1;FALSE)
I got the same outcome.. I checked one random value (1/1/16 3:00) to check if the two cells with the same value are equal using the command : =A3=N5 and I got TRUE ..which means that the two cells are matching.
What do you think? What is the problem?
First check that either both columns are numeric values formatted as dates or both columns contain text.
If you imported the data, sometimes different characters are used for Space. Try a find and replace (ctrl+H). Enter a Space character in both the "Find what:" and "Replace with:" fields.

Two Column Lookup

I have a data set that I want to return an indexed column using two values: a year and a name. Both these values are formatted to general (I also tried text) in my spreadsheet.
In one work sheet I have a like of people:
On the other, I have a table of Years, Names, and a number
I am trying to do a lookup on the joined year and name and return the given number in the second table. For instance 2013Andrew McCutchen would return 8.2, and 2014Andrew McCutchen would return 6.8.
Currently, I only get the #N/a value with the following"
=INDEX('2006 Results'!C2:C556,MATCH($J$1&C3,'2006 Results'!$A$2&$B$556,0))
But, I know a certain value is in the table though because I have tested with an if statement to make sure my spelling is correct. Any guidance would be much appreciated.
I would add a column to the left of the year column as column A to contain the following formula in cell A2 which refers to the year and name column:
=$B2&$C2
You can then use this column in a VLOOKUP formula on the people sheet. Cell J3 would read as follows. Copy this to all cells in the table body.
=VLOOKUP(J$1&$C3,'TheYearSheet'!$A$1:$D$556,4,false)
Job done.
In your match expression, you are comparing one concatenated value $J$1&C3 to another single concatenated value '2006 Results'!$A$2&$B$556. Match expects that second parameter to be a range rather than a single value.
In cases like this, where multiple criteria are required, I prefer to use sumifs rather than index-match, even though the intention is to return a single value. I think =SUMIFS('2006 Results'!$C:$C,'2006 Results'!$A:$A,j$1,'2006 Results'!$B:$B,$c3) will give what you need and should correctly copy to the other cells in that table.

Find the latest value in a row then enter the date in a cell

If you look at the image below we are trying to get a formula working, so we can do the following.
In Row 6 we need to locate the last Full in the column that is the date before the current date.
So for Blandc01 we have a full in Row 6 and column UJ6. WE need to find the latest Full in that column and then put the date at the top of that column in the cell that says Last Full in this case it's B12.
If for example you look at Blanbck01, we have our last full on 04/07/2014 in column UF, so the cell B8 has that date in it from Cell UF6.
So how do we use a series of functions to determine the last Full in the respective row, find that date of the column and put this in the relevant cell on the left.
I have updated the image to include the row numbers.
Thanks to pnuts comments, it is apparent that a lookup using just "full" won't work on an unsorted list. So here is one that will
=IFERROR(LOOKUP(2,1/(C5:XD5="full"),$C$3:$XD$3),"")
You will need to change the row references to properly reflect the two vectors. The first array is the row where you are looking for "full", the second is where the dates are located.
The OP has been asking more questions in the comments section. It seems he wants to return the latest dates where either "full" or "syn.full" is seen in the particular line.
If merely looking for the substring "full" will be sufficient (in other words, if there are no other strings that contain "full" that need to be excluded, then one can use:
=IFERROR(LOOKUP(2,1/ISNUMBER(SEARCH("full",C6:XD6)),$C$3:$XD$3),"")
On the other hand, if there might be other strings containing "full" which we want to ignore (e.g. fullness), and if the dates in row 3 are in ascending order, then try the following:
=MAX(IFERROR(LOOKUP(2,1/(C6:Z6="full"),$C$3:$Z$3),0),IFERROR(LOOKUP(2,1/(C6:Z6="syn.full"),$C$3:$Z$3),0))
If you use the latter, you should format the cell to not show 0's (eg: yyyy-mm-dd;; ) or wrap the whole formula in an IF to return the null string if the result is zero.
Finding the last match is always more difficult than the first one but I think I have something that works. This is an array function so has to be entered with ctrl+shift+enter
=indirect("R3C" & max((UB6:UJ6="full")*column(UB6:UJ6)),FALSE)
A break down of the function is as follows
(UB6:UJ6="full") returns an array of 1s and 0s (1 where it evaluates true). This is then multiplied by the column number (given in numbers, not letters). Once these are multiplied together we have a list of all the columns that have the word "full"
The indirect function allows you to use R1C1 style formulas if the second variable is False so the column can be inputted directly as a number. The R3 at the beginning means the value returned with be in row 3.

Querying a table that CONTAINS wildcards

Short version:
Basically I want to do this, but in excel. Instead of querying a table USING wildcards, I want to query a table that CONTAINS wildcards.
Long version:
I'm creating a spreadsheet to summarize my bank account transactions at the end of each month. I want to organise the transactions in my bank statement into categories like "groceries", "entertainment", "fuel" etc and then sum up the total amount spent on each category.
I have a sheet that acts as a database, with a list of known account names for each category (e.g. under "clothing" I have the names of the accounts of all the clothing stores I go to). I then have another sheet with the first two columns containing transactions (account name, and amount), and then a column for each category. I copy each amount in column 2 into the correct category column using the following formula:
=IF(ISNA(MATCH($B2,database!B:B,0)),"",$C2)
Where column B is the "account name" column from my bank statement, and column C contains the amounts.
This works fine as long as the data in the database worksheet is an exact match. But a lot of the account names are similar e.g. "7elevenl12345", "7eleven836549" etc. How can I add strings with wildcards like "7eleven*" to my database?
Thanks in advance.
You can use SEARCH for all the column B values in B2, although better to restrict the range so I'll use rows 2 to 100
=IF(ISNUMBER(LOOKUP(2^15,SEARCH(Database!B$2:B$100,$B2))),$C2,"")
SEARCH automatically searches for a value within other text so no wildcards required [you should remove wildcards from the database you only need "7ELEVEN" etc.]. If one (or more) of the searches is a match then it will return a number and so will LOOKUP so you can test whether it does or not.
SEARCH function is not case-sensitive, change to FIND if you want the match to be case-sensitive
Explanation:
When you use
=SEARCH(Database!B$2:B$100,$B2)
That returns an "array" the same size as Database!B$2:B$100. For each value in Database!B$2:B$100 you either get a number (if that specific value is found within B2 it's the position of the start of that value) or you get #VALUE! error.
Then when you lookup a "bignum" like 2^15 in that array, i.e.
=LOOKUP(2^15,SEARCH(Database!B$2:B$100,$B2))
That returns the last number found in the array....or #N/A if there are no matches, so using ISNUMBER identifies whether there is at least one match or not.
If you want to see the whole array returned by
=SEARCH(Database!B$2:B$100,$B2)
then put that in a cell and then select that cell, press F2 to select the formula and F9 to see the whole array.
If you have blanks in Database!B$2:B$100 then that's a problem because a blank is always "found" in any value (at position 1) so you can edit the formula to prevent that, i.e.
=IF(ISNUMBER(LOOKUP(2^15,SEARCH(Database!B$2:B$100,$B2)*(Database!B$2:B$100<>""))),$C2,"")
both versions of the formula can be shortened by using COUNT in place of LOOKUP and ISNUMBER, i.e. for that latter version you can use
=IF(COUNT(SEARCH(Database!B$2:B$100,$B2)*(Database!B$2:B$100<>"")),$C2,"")
but that version needs "array entry" - i.e. you need to confirm the formula with the key combination CTRL+SHIFT+ENTER such that the formula is enclosed in curly braces like { and }
Note: 2^15 is used here because it is guaranteed to be a larger number than any number that SEARCH function can return. 2^15 = 32768 but the maximum number of characters in a cell is 1 fewer than that - 32767
You would to change your formula to: =IF(ISNA(MATCH($B2&"*",database!B:B,0)),"",$C2)
I think this is what you're looking for.

Resources