In Excel, I am trying to return the two-letter country codes from email addresses in column C (e.g. "fr" for France), but ignoring generic TLDs such as "com", "net", etc. I do not want to use only =RIGHT(C2,2), which works OK, because this would return e.g. "om" from ".com" - "om" is the country code for Oman.
I have tried using the following formula, however this returns False, because RIGHT(C2,3) is three characters and cannot only equal "."
=IF(RIGHT(C2,3)=".",RIGHT(C2,2),"")
Could someone please indicate if there is a way to use If with a specific character "." in the third position from the right?
So a quick start:
IF(LEFT(MID(H2,LEN(H2)-2,3),1)=".",MID(H2,LEN(H2)-2,3),"")
And tested:
So, you may need to improve it as I have not trapped for any errors.
A few further tests:
BTW I can now wrap this in a lookup to retrieve the country name directly, e.g.
=XLOOKUP(IF(LEFT(MID(H2,LEN(H2)-2,3),1)=".",MID(H2,LEN(H2)-2,3),"") lookup_array, return_array)
Using list of country codes and countries taken from Wikipedia's list of country TLDs
Related
I have the column as you can see in this image.
The Distributor Address is in the format: "Street Address, Postcode, State".
I need to retrieve only "Postcode" and "State" and combine them.
The new column should be like this ➡"NSW2007","VIC3182"...
How could I retrieve the specific letters and combine them?
You can use FILTERXML if you have the newest version of Excel. See Excel - Extract substring(s) from string using FILTERXML for an excellent overview.
In this case, something like the below should work:
EDIT: overlooked the specific format you wanted
=FILTERXML("<t><s>"&SUBSTITUTE(A1,",","</s><s>")&"</s></t>","//s[3]")&
FILTERXML("<t><s>"&SUBSTITUTE(A1,",","</s><s>")&"</s></t>","//s[2]")
Well, here is a different way:
=RIGHT(A2,3)&","&TRIM(MID(A2,FIND(",",A2,1)+2,LEN(A2)-FIND(",",A2,FIND(",",A2,1)+1)))
This does rely on the state being the last 3 characters and the postcode after the first comma...
There are several ways of solving that. I will show a solution using a few basic functions: RIGHT, MID and LEN.
Assuming your data is on A1:
=RIGHT(A1,3)&MID(A1, LEN(A1)-8, 4)
RIGHT returns the 3 last characters from the cell A1.
MID returns the middle of the cell given a starting position and a length.
LEN gives you the starting position of the zip code, which is always the length of the string - 8 in your table.
Is it essential that your data is well organized as in the image to work well. One alternative is finding the ", " as below.
=RIGHT(A1,3)&MID(A1, FIND(", ",A1)+2,4)
I have a list of email names such as this:
Name.Surname#domain.com
Anothername.Anothersurname#domain.com
I'm trying to figure out an excel formula, that would do the following:
John.Doe#domain.com would be translated into an ID - JD
Nick.Doe#domain.com would be translated into an ID - ND
However, I want to make sure if there's a John.Doe and a Jane.Doe, that they'd get ID's that aren't the same (so for example it would be JD1 and JD2).
So essentially, I don't want to have two JD, but JD1 and JD2.
How would I achieve that with excel?
Thanks!
Use:
=UPPER(LEFT(A1)&MID(A1,FIND(".",A1)+1,1))&TEXT(COUNTIF($A$1:A1,LEFT(A1)&"*"&"."&MID(A1,FIND(".",A1)+1,1)&"*"),"00")
this will always put a two digit number behind the initials, regardless of number of employees with those initials.
I have 2 column data in Excel like this:
Can somebody help me write a formula in column C that will take the first name or the last name from column A and match it with column B and paste the values in column C. The following picture will give you the exact idea what I am trying to do. Thanks
Since your data is not "regular", you can try this formula which uses wild card to look for just the last name.
=INDEX($B$1:$B$4,MATCH("*" &MID(A1,FIND(" ",A1)+1,99)&"*",$B$1:$B$4,0))
It would be simpler if the first part followed some rule, but some have the first initial of the first name at the beginning; and others at the end.
Edit: (explanation added)
The FIND returns the character number of the first space
Add 1 to that to get the character number of the next word
Use MID to extract that word
Use that word in MATCH (with wild-cards before and after), to find it in the array of email addresses. This will return it's position in the array (row number)
Use that row number as an argument to the INDEX function to return the actual email address.
If you want to first examine the email address, you will need to determine which of the letters comprise the last name. Since this is not regular according to your example, you will need to check both options.
You will not be able to look for the first name from the email, as it is not present.
If you can guarantee that the first part will be follow the rule of one or the other, eg: either
FirstInitialLastName or
LastNameFirstInitial
Then you can try this:
=IFERROR(INDEX($B$1:$B$4,MATCH(MID(A1,FIND(" ",A1)+1,99)& LEFT(A1,1) &"*",$B$1:$B$4,0)),
INDEX($B$1:$B$4,MATCH( LEFT(A1,1)&MID(A1,FIND(" ",A1)+1,99) &"*",$B$1:$B$4,0)))
This seems to do what you want.
=IFERROR(VLOOKUP(LOWER(MID(A1,(SEARCH(" ",A1)+1),LEN(A1)))&LOWER(MID(A1,1,1))&"*",$B$1:$B$4,1,FALSE),VLOOKUP(LOWER(MID(A1,1,1))&LOWER(MID(A1,(SEARCH(" ",A1)+1),LEN(A1)))&"*",$B$1:$B$4,1,FALSE))
Its pretty crazy long and would likely be easier to digest and debug broken up into columns instead of one huge formula.
It basically makes FLast and FirstL out of the name field by splitting on the space.
LastF:
=LOWER(MID(A1,(SEARCH(" ",A1)+1),LEN(A1)))&LOWER(MID(A1,1,1))
And FirstL:
=LOWER(MID(A1,1,1))&LOWER(MID(A1,(SEARCH(" ",A1)+1),LEN(A1)))
We then make 2 vlookups for these by using wildcards:
LastF:
=VLOOKUP([lastfirst equation from above]&"*",$B$1:$B$4,1,FALSE)
And FirstL:
=VLOOKUP([firstlast equation from above]&"*",$B$1:$B$4,1,FALSE)
And then wrap those in IfError so they both get tried:
=IfError([firstLast vlookup],[lastfirst vlookup])
The rub is that's going to be hell to edit if you ever need to, which is why I suggest doing each piece in another column then referencing the previous one.
You also need to be aware that this answer will get tripped up by essentially the same name - e.g. Sam Smith and Sasha Smith would both match whatever the first entry for ssmith was. Any solution here will likely have the same pitfall.
I'm attempting to create usernames based off of a given persons first and last name. Generally, we use the first initial and last name for a username. However, now many of our users have 2 last names and sometimes include a hyphen. I am trying to create a code that gives me the first initial, the first letter of the FIRST last name and then the last name.
For example --
Amy Smith-Jones ==
asjones
This is what I am currently using, but, of course, it would yield "asmithjones".
=LOWER(LEFT(A1,1)&SUBSTITUTE(SUBSTITUTE(A2,"-","")," ",""))
I've tried some variations of this, but with no luck.
=LOWER(LEFT(A1,1)&LEFT(A2,1)&SUBSTITUTE(SUBSTITUTE(A2,"-","")," ",""))
Is there a way to generate both the first letter of the first string and the full text of the 2nd string?
EDIT
I came up with something, but now I face another challenge
=IFERROR(LOWER(LEFT(D2,1)&SUBSTITUTE(SUBSTITUTE(RIGHT(F2,LEN(F2)-FIND(" ",F2&" ")),"-","")," ","")),LOWER(LEFT(D2,1)&SUBSTITUTE(SUBSTITUTE(F2,"-","")," ","")))
Some users have 1 last name so this applies if the formula comes across those. But I have some who have a hyphen instead of a space. The SUSTITUTE function accounts for both, but how can I make the FIND function do the same?
Try:
=LEFT(A1,1)&MID(A1,(SEARCH(" ",A1)+1),1)&RIGHT(A1,(LEN(A1)-(SEARCH(" ",(SUBSTITUTE(A1,"-"," ")),(SEARCH(" ",A1)+1)))))
Based on your edit, I'll assume first names are in column D and last names are in column F:
=LOWER(LEFT(D2) & IFERROR(LEFT(F2)&MID(F2,FIND("-",SUBSTITUTE(F2," ","-"))+1,99), F2))
SUBSTITUTE changes spaces to hyphens in the last name, so FIND can look for hyphens only.
IFERROR fails if a hyphen is not found (after substitution), in which case the entire last name is returned.
Example:
I have the list with like 100,000 site link strings
Each link is unique, but it has consistent ?Item=
Then, it's either nothing or it continues after & symbol.
My question is: How do I pull out the item numbers?
I know replace function can offer similar functionality, but it works with Fixed sizes, in my case string can be different in size.
Link example:
www.site.com?sadfsf?sdfsdf&adfasfd?Item=JGFGGG55555
or
www.site.com?sadfsf?sdfsdf&adfasfd?Item=JGFGGG55555&sdafsdfsdfsdf
In both cases I need to get JGFGGG55555 only
If this always is the last portion of the string, you can use the following:
=MID(A1, FIND("?Item=", A1) + 6, 99)
This assumes:
no item numbers will be over 99 digits.
no additional fields follow the item number.
Edit:
With the update to your question, it is apparent you have some strings with additional data after the ?Item= field. Without using VBA there is not a simple means of using MID and FIND to extract this.
However you could create a column which acts as a placeholder.
For example, create a column using:
=MID(A1,FIND("?Item=",A1)+6,99)
This gets you the following value: JGFGGG55555&sdafsdfsdfsdf
Next, create a column using:
=IF(ISERROR(FIND("&",B2)),B2,LEFT(B2,FIND("&",B2)-1))
This produces: JGFGGG55555 by searching the first value for a & and using the portion before it. If it is not found, the first value is simply repeated.
This formula should work for both the examples given:
=MID(A1,FIND("=",A1),IFERROR(LEN(A1)-FIND("&",A1,FIND("=",A1))-1,LEN(A1)+1-FIND("=",A1)))