partial match excel with different languages - excel

I have 2 different columns in excel and both are containing address lines but in different languages 1 in English and 2nd in Japanese, How can I do the partial match just the based upon the last numeric numbers of both the address.
Please take a look in the attachment to better understand.
My data set looks like this

So, first issue is address 1 does not have a number on the right.
Now, for address 2 you could use :
=right(B1,8)
which will bring back the last 8 characters ie the 7 digits with the hyphen. You could match to that result as you wish, assuming the data for adrress 2 is in column B.
Image as proof:

As per your data sample, in English address the number you are looking for is separated by comma and is coming at start, For example in 3-10-31, AMAVAMA, you can look for 3-10-31 which is separated by a comma from rest of the address
If this is the case in most of the cells you can use the below formula
Considering your Address 1 is in column B, Address 2 is in column C and the formula is in column A
=INDEX($C$2:$C$5,MATCH(1,IF(IFERROR(SEARCH(LEFT(B2,FIND(",",B2)-1),$C$2:$C$5),0)>0,1,0),0))
the formula is in cell A2 and is an array formula

Related

Excel automatically converting 7 digit CAS number to another number (date?)

Problem: I am working with 2 list. One called HYPHEN and one called CAS Number in columns A and B respectively.
Column C uses a formula that combines column A and B and sorts them such that if a hyphen is present in column A, this is inserted before the adjacent CAS number which is then inserted below and the sequence continues so that all hyphens and CAS numbers are included. I've attached an image to better explain this and the Formula to replicate this is given below.
A CAS number is a unique Identify for a material/chemical and usually is written as 000-00-0, however occasionally you get materials with CAS numbers of 0000-00-0 (or other variations).
For the most part column C is correct because all but one CAS numbers are in the usual format. However As highlighted in red 6132-04-3 is being converted to 1545801.
What I have tried:
I have realised that 6132-04-3 is being converted to 03/04/6132 so I'm pretty sure that this is being recognised as a date which is causing the problem. I have tried to format the cells to all be a text format, I have added a comma before the CAS number but nothing returns the desired value of 6132-04-3 and instead always returns 1545801.
To replicate the issue: Column A and B can have any data entered. To replicate the output of column C the formula is given below:
Formula for Column C:
=FILTERXML(""&SUBSTITUTE(TEXTJOIN(",",TRUE,A2:B26),",","")&"","//b")
(Formula provided by #Gary's Student on Stack Overflow)
Any thoughts on how to prevent the red CAS number being converted when it is sorted in Column C would be really appreciated.
This is a crude way to fix it by adding then removing an arbitrary character:
=MID(FILTERXML("<a><b>"&SUBSTITUTE(TEXTJOIN(",",TRUE,IF(A2:B26="","","x"&A2:B26)),",","</b><b>")&"</b></a>","//b"),2,99)
If you have the issue of some of your strings containing a comma, just use a different separator:
=MID(FILTERXML("<a><b>"&SUBSTITUTE(TEXTJOIN("|",TRUE,IF(A2:B26="","","x"&A2:B26)),"|","</b><b>")&"</b></a>","//b"),2,99)
Looks like you could use:
Formula in D2:
=SUBSTITUTE(FILTERXML("<t><s>'"&TEXTJOIN("</s><s>'",,A2:B10)&"</s></t>","//s"),"'","")
Or:
=MID(FILTERXML("<t><s>'"&TEXTJOIN("</s><s>'",,A2:B10)&"</s></t>","//s"),2,99)
I can suggest you this:
Go to Format Cells ---> Number ---> Custom ---> Type
In this "Type" field write this #000-00-0
Press "OK"

Excel: Find matching row with numerical range

I have a spreadsheet with Company Name and Serial Number columns. The serial number column values are in range e.g. 1001-2000. How do I look up company name from a specific serial number value? See this screenshot for example.
Column B can be split into two columns if needed though it is preferable to have single column.
I tried this example but got a #Spill! error
Or, using Lookup+Imreal function
In E2, enter formula:
=LOOKUP(D2,IMREAL(B2:B5&"i"),A2:A5)
Be careful with this... It is a crude hack.
=IF(D2<=1000,A2,INDEX(A:A,MATCH(D2+1&"-"&D2,B:B,1)))
in the special case of the ranges all ending at a multiple of 1000 and each band being essentially 1000 units you could go with the special case formula of
=INDEX($A$2:$A$5,INT(($D2-1)/1000)+1)
Note that you don't actually use the info in column B for this option. It is based purely on the pattern to the range breakdown
if you want to restrict it to values between 1 and 4000 you could wrap it in an if statement that checks for that.
=IF(AND(D2>=1,D2<=4000),INDEX($A$2:$A$5,INT(($D2-1)/1000)+1),"SN out of range")

Check for one, two or three digits in a VLOOKUP

I have around 30 numbers which are either 1, 2 or 3 digits which are codes. These codes are attached in front of other numbers. I want to know what code is in front of a number, for example for the number 35467036 the first two digits matches with the code 35. So I want the output for that to be 1.5.
This is my current setup, I have a table with all the codes followed by the output in the next column. If all the codes were three digits long I could just do this =VLOOKUP((LEFT(E6,3)&"*"),D1:E3,2,FALSE) but they are unfortunately not.
I have also tried using nested IF statements but I can only go so far as 7 levels.
Will this only be possible in VBS or is there anther way?
Edit:
The code column is formatted to text. If I enter the value 3 into LEFT it does not work for two digits. Is there anyway I can make it work for 1, 2 and 3 digit codes? Also the codes do not overlap, for example, there isn't going to be 96 and 965 in the code table.
Seven nested IFs as a limit points to a very old version of Excel. You may want to consider upgrading to a version that is still supported in this millennium.
But your main problem is that the data type of your lookup value is text, because you concatenate a string with a wildcard. Whereas your Lookup Table's first column is probably made up of numbers.
In order to solve this you will need to add a Text column to your lookup table that represents the numeric value as a text value.
IF you want to use Vlookup, that helper column will need to be the first column of your lookup range.
You can use an Index/Match instead of Vlookup to be independent of the column order, as this screenshot shows:
Column H shows the formula that has been applied in column G.
Edit:
According to the screenshot you posted, you want to look up from the table in columns E to F and this table only has the short codes. Therefore, it makes no sense to add a wildcard to the lookup value. You just need to extract the value you want to use for the lookup.
If you want to lookup only two digits, then you need to extract only two digits. Adding a wildcard does nothing to remove the third digit.
In the screenshot below, a helper column feeds the LEFT() function the number of characters to extract, then uses that value in the VLookup.
=VLOOKUP(LEFT(A1,B1),$E$1:$F$5,2,FALSE)
=INDEX($G$2:$G$5,
SMALL(
IF(LEFT(A1,3)*1=$F$2:$F$5,ROW($G$2:$G$5)-1,
IF(LEFT(A1,2)*1=$F$2:$F$5,ROW($G$2:$G$5)-1,
IF(LEFT(A1,1)*1=$F$2:$F$5,ROW($G$2:$G$5)-1))),1))
=INDEX(LookupValues,Small(ArrayOfRowsFromIfStatements,FirstRow))
This is an array formula so you will need to use Ctrl+Shift+Enter while still in the formula bar.
We use If to build an array of Row numbers where the conditions match or return FALSE if not. The Small function then returns the smallest result in the array which will be the first row where conditions match.
We then index the results returning that row number (-1 deducted from rows to offset the headers).
If your numbers in column A are always 6 digits + the code length you can use this:
=VLOOKUP(--LEFT(A1,LEN(A1)-6),E2:F5,2,FALSE)

Excel: How to copy specific cell data (zip codes) into a new column

I have two columns of cells that have irregularly formatted addresses.
I need:
1) just the zip codes to be copied into a new column;
2) the rows that do not contain zip codes to be either highlighted or empty so that I can easily identify which ones are missing.
This seems like it would be simple to do, but I can't figure out how to have Excel just find all instances of 5 consecutive numbers. Currently they are formatted as text so that the zero's are displayed. Any help greatly appreciated.
Here's what it would be to start with:
Here's what it would look like when done (highlighting optional):
You don't have Regular Expression in normal Excel. You would have to go into VBA to do that. However, for your case, there's an easy pattern: notice how the zip code is after the last space, and it's always 5 digits long? The challenge then become finding the index of this last space and extract the 5 characters that follow it. It will be clearer if you split them into 2 formula
// C3 (index of last space character):
=FIND("|",SUBSTITUTE(B3," ","|",LEN(B3)-LEN(SUBSTITUTE(B3," ",""))))
// D3, the 5 characters after that.
// Return an empty string if the address doesn't match the pattern
=IFERROR(MID(B3,C3+1,5),"")
Another approach to what Zoff Dino wrote is to break it out a bit as shown below:
In cell C3 enter the formula you see in the formula bar
Drag that down the row set and over 1 column (so it runs for column B as well)
In column use this formula: =IF(AND(C3="",D3=""),"",IF(C3="",D3,C3)) and drag it down.
This will account for all possible situations you have shown and not error out on you (unless other patterns emerge).
You can then use conditional formatting to highlight the rows with no zip code as shown in the picture:

How can I take a certain characters from a cell of a different spreadsheet

I have a problem with my current code from Excel VBA.
I need to take only the last four digits from another spreadsheet, but it doesn't seem to be possible.
I'm currently using the Sheets("Sheet2").Cells(y, cOTr).Value instruction to take values of other spreadsheets and the LEFT(a,2) and RIGHT(a,2) instructions to take only specific characters of a string data.
I just can't find a way to combine those two instructions.
E.g. I want to copy only the first 4 numbers of Cells from the second column from sheet 2, which has the numbers similar to 6657-2 in it, to sheet 1.
Sorry if my explanation wasn't clear enough.
Edit: Lets's say I want to make a comparison between a table from spreadsheet 1 and a table from spreadsheet 2: the first table has values with four digits (e.g. 3333) and the second has values with 4 digits, a hyphen and another digit (e.g. 2222-3). I need to make a comparison between table 1 and 2, which are from different spreadsheets and to do that I only need the first four digits from table 2. I already have the logic for the program and it's running perfectly with some tests I did with only 4 digit numbers, I only need a way to take those first four numbers, something like using the "left(cells(1,2),2)" instruction but with cells of another spreadsheet.
You can combine text / strings by using the ampersand operator &
e.g.
=LEFT(A2,2) & RIGHT(A2,2)
Alternatively, you can also use CONCATENATE
e.g.
=CONCATENATE(LEFT(A2,2),RIGHT(A2,2),"some other string","and so on")
you can us this formula: =LEFT(Sheet2!A1,4).
Sheet2 A1 is where you have data 2222-3.

Resources