How can I switch a string from "lastName, firstName" to "firstName LastName"? - string

I have a column full of names written as:
"lastName, firstName"
I want to have a nother column that has this name list written as:
"firstName LastName"
So, how can I switch a string from "lastName, firstName" to "firstName LastName" ?

If the first name is in A2 try this formula in B2 copied down
=MID(A2&" "&A2,FIND(" ",A2)+1,LEN(A2)-1)

Enter data into cells e.g.
Brown, John
Green, Bob
Smith, Will
(Note that the comma in this case is the delimiter which the system will use to separate the entries)
Highlight these cells.
Click on the "Data" tab,
click on "Text to Column".
Choose options offered.

The worked for me
=RIGHT(C3,LEN(C3)-LEN(LEFT(C3,FIND(",",C3)-1))-1) & " " & LEFT(C3,FIND(",",C3)-1)

Barry's answer is correct, if the single cell (A2) doesn't ALSO contain errors like "firstname lastname" -- as is often the case.
So, to deal with the cell data being either "Last, First" or "First Last", we'll need to compare the cell and take action appropriately. Also note, in my example, I moved the first name to it's own column, and last name to it's own column. You can of course join them into a single column.
First, let's break down what we need. This will return the first name when there is a "," in the cell contents: (assumes the field you are wanting to split is in A2, adjust as needed)
=MID(A2;FIND(",";A2)+2;99)
and this will return the first name when there isn't:
=MID(A2;1;FIND(" ";A2))
And for Last name when there is a comma:
=MID(A2;1;FIND(",";A2)-1)
and last name when there isn't:
=MID(A2;FIND(" ";A2)+1;99)
So, we need to test if there is a "," in the string, and deal with an error condition when there isn't (FIND returns #value when not found, ISERROR() can test for that). Optionally (and my approach) was to check if the return of the FIND yielded a number (an error won't). In this case, an "error condition of not finding it" would yield a non-number #Value.
=IF( ISNUMBER( FIND(",";A2)); MID(A2;FIND(",";A2)+2;99); MID(A2;1;FIND(" ";A2)))
Doing the same thing for the Last name looks like this:
=IF( ISNUMBER( FIND(","; A2)); MID(A2;1;FIND(",";A2)-1); MID(A2;FIND(" ";A2)+1;99))
Please note that my solution was using my spreadsheet application OpenOffice. I think Excel has a different find method (Search?) - so make adjustments as necessary.

The above answer is incorrect.
In fact, for my own name, Jay Jacob Wind, the formula breaks.
The correct formula is:
Assuming Last, First is in column A, separated by one comma and a space bar
For first name:
=mid(A2,find(",",A2)+2,99)
For last name:
=mid(A2,1,find(",",A2)-1)
Put together, assuming Column B is First Name and Column C is Last Name
=B2&" "&C2
or simply (but more complexly)
=mid(A2,find(",",A2)+2,99)&" "&mid(A2,1,find(",",A2)-1)
but I like separating them into two columns,
then concatenating them

Related

Splitting names given in single cells without using text to column excel

i want to use excel formula to split multiple names given in a single cell. dont want to use text to column feature. For example
in the above yellow is the variable name & the green color is the required format
See find the nth instance of a character: FIND(CHAR(1),SUBSTITUTE(string,delimiter,CHAR(1),nth)). For the first, we use LEFT(string,position_first-1). For the last: RIGHT(string,LEN(string)-position_last). For all in between: MID(string,position_first+1,position_second-position_first-1).
So, combining the logic, we may get this:
=IFERROR(IFERROR(IF(B$1=1,LEFT($A2,FIND(CHAR(1),SUBSTITUTE($A2,"/",CHAR(1),1),1)-1),MID($A2,FIND(CHAR(160),SUBSTITUTE($A2,"/",CHAR(160),B$1-1),1)+1,FIND(CHAR(1),SUBSTITUTE($A2,"/",CHAR(1),1+B$1-1),1)-FIND(CHAR(1),SUBSTITUTE($A2,"/",CHAR(1),B$1-1),1)-1)),RIGHT($A2,LEN($A2)-FIND(CHAR(1),SUBSTITUTE($A2,"/",CHAR(1),B$1-1),1))),"")
IFERROR(...,"") is used to return "" after last occurrence (below, in G2). Nested IFERROR(... RIGHT) will be triggered at last occurrence (since MID will fail there; below at F2).
Try using this:
With the full name in cell A2, the formulas go as follows:
Get the first name:
=LEFT(A2,SEARCH(" ",A2)-1)
Get the last name:
=RIGHT(A2,LEN(A2)-SEARCH(" ",A2,1))
You enter the formulas in cells B2 and C2, respectively, and drag the fill handle to copy the formulas down the columns. The result will look something similar to this:

In Google Sheets or Excel, how do I search for values that are similar?

What I'd like to do is the following:
I have one file with 3 sheets (tab1, tab2, and tab3). In each, I have the column name "Company Name" and in tab1 I have two specific columns named 'tab2' and 'tab3' that represent the sheets tab2 and tab3. What I'd like to do is query the sheets tab2 and tab3 to see if there are company names that either match 100% or are similar to what's listed in the 'Company Name' column in tab1.
Example:
Tab1
Company Name
Great Shoes
Tab2
Company Name
Great
Tab3
Company Name
Greatness Shoes Inc
So in the above-mentioned scenario, I'd like to then input into the columns tab2 and tab3 in the sheet tab1 whether or not there was a partial match with a yes or no.
What is the best formula to do this in Excel or Google Sheets? I tried it in Excel but got as far as finding out partial matches with very low accuracy using this formula:
=IF(ISNA(VLOOKUP(B2 "*",'tab2'!$A$2:$A$884,1,FALSE)), "No", "Yes")
google-spreadsheets has regex functions.
You may try:
combine all the data in a single sheet (column A) to simplify the comparison
use the formula:
=TEXTJOIN(";",1,FILTER(A:A,REGEXMATCH(A:A,A1) + REGEXMATCH(A1,A:A),A:A<>A1))
Notes:
The formula does not give a 100% match, you still need a human to look for misspellings.
The formula will give all found matches divided by semicolon
if no matches are found, the cell will be left blank
you may manually add some keywords to your list in order to combine similar company names: like a word "Great", which matches all companies with this word inside.
paste it in B1 and copy down.
You could use a combination of ARRAYFORMULA, ISNUMBER, and SEARCH. Using the "great shoes" example from Max, if your data is in column, A in B1 you could put:
=ARRAYFORMULA(IF(ISNUMBER(SEARCH("Great",A:A))=TRUE,A:A,""))
So that searches column A for the string "Great." If it is found =TRUE then whatever is in that cell is returned. If nothing is found ,FALSE, then a blank is returned "". There would not be any need to "copy down." You could modify that "if true" and "if false" statements to modify data as you need. In place of the "Great" string, you could put a cell reference.
You could also use QUERY in a manner similar to ISNUMBER(SEARCH. In B1 you could put =QUERY(A:A,"Select A where A contains 'Great'",0)
You could also use INDEX and MATCH. If your DATA is in column A in B1 you could put something like =INDEX($A1:$A3,MATCH("Great",$A1:$A3,FALSE)). You would have to "copy down" the formula for each row. If you want to prevent the #N/A error from showing, wrap that all in an IFERROR formula. =IFERROR(INDEX($A1:$A3,MATCH("Great",$A1:$A3,FALSE)),"").

Parsing out First and Last name from Excel field

I have a field (column) in excel in the format of "LastName, FirstName MiddleInitial" with a space between the comma after the last name and the first name and a second space between the middle initial and the first name (no comma after the first name). Is there a way to identify which cells have a middle initial on the right hand side and then eliminate the middle initial for all cells such that the output will look like "LastName, FirstName"?
Thanks!
What you want to do is to be able to parse the field into multiple fields, and then rejoin then with a simple excel formula. To take a field and put it into multiple columns you can use the following approach for "Text to Columns"
Text to Columns
Once you have 3 columns of text, you can group the first two together by using a formula like =A1&", "&B1 in the column you want to have the value. (In my example, the last name would be in A1, and first name in B1)
You could also do it as a cell formula without changing your original data. I built this up using the models presented on How to split a string based on “:” in MS-Excel?, over at SuperUser.
Assuming you have a name (Public, John Q) in a1:
=LEFT(A1,FIND(" ",A1)) & LEFT(MID(A1,FIND(" ",A1)+1,LEN(A1)),IFERROR(FIND(" ",MID(A1,FIND(" ",A1)+1,LEN(A1)))-1,LEN(MID(A1,FIND(" ",A1)+1,LEN(A1)))))
It looks very complicated, but really isn't:
Using these two components:
Get everything to the left of the first space in a string: LEFT(A1,FIND(" ",A1))
Get everything to the right of the first space in a string: MID(A1,FIND(" ",A1)+1,LEN(A1)))
We can grab these pieces:
Get the last name: LEFT(A1,FIND(",",A1)+1)
Get the first name and middle name: MID(A1,FIND(" ",A1)+1,LEN(A1)))
Then recurse by putting the "left of a space" construction around the "right of a string" construction:
MID( LEFT(A1,FIND(",",A1)+1) ,FIND(" ", LEFT(A1,FIND(",",A1)+1) )+1,LEN( LEFT(A1,FIND(",",A1)+1) )))
Unless there is no second space (when there's no middle name.) That's what the Iferror is for - in that case, you want the entire length of what you got after the first space:
LEFT(MID(A1,FIND(" ",A1)+1,LEN(A1)),IFERROR(FIND(" ",MID(A1,FIND(" ",A1)+1,LEN(A1)))-1,LEN(MID(A1,FIND(" ",A1)+1,LEN(A1)))))
Put them together for lastname, firstname:
=LEFT(A1,FIND(" ",A1)) & LEFT(MID(A1,FIND(" ",A1)+1,LEN(A1)),IFERROR(FIND(" ",MID(A1,FIND(" ",A1)+1,LEN(A1)))-1,LEN(MID(A1,FIND(" ",A1)+1,LEN(A1)))))

How do I parse text in excel?

If my selected fields contain the word "xxx" or "yyy", I want to change those fields to show only those words. If a field doesn't contain either, I want to delete the info in that field.
How can this be done in excel?
I think you might want to use an IF expression here.
For example:
=IF(OR(A1="xxx",A1="yyy"),A1,"no")
If in column A you place xxx, yyy, zzz each in their own row. Then in column B you place this formula and replicate it down to row B3 you should find that if "xxx" or "yyy" is present in the cell then the value is displayed, otherwise "no" is displayed. You could change no in the formula to an empty string "" to get the effect of deleting the contents.
For further reading on the Excel IF expression see http://www.techonthenet.com/excel/formulas/if.php
The worksheet formula you would use to determine if the cell 'contains' xxx or yyy, then perform the action you requested would be:
=IF(NOT(ISERROR(FIND("xxx",A1))),"xxx",IF(NOT(ISERROR(FIND("yyy",A1))),"yyy",""))
However I want to point out that, in this case, "xxx" will override "yyy" in the case where the cell value is, say, 'abcyyydefxxx'...the result would be "xxx".
If there is a chance that a cell could contain both of your strings, I will revise the formula to accommodate that.
Now, the A1's in the formula point at the cell you are checking.

Find duplicate and mark as 1st and rest of the dup mark with "Other Dups"

I have an excel file that I need to make some changes. I need to identify the duplicate and then put "1st" in the series column for the first dup. For the remainder dups need to put "other dups" in the series column. Is it possible? I tried vlookup and match and nothing helped. =vlookup(a1,a2,0) , match(a1,a2,0), or even if(a1=a2,"found match")
If data starts at A2 try this formula in B2 copied down
=IF(COUNTIF(A:A,A2)>1,IF(COUNTIF(A$2:A2,A2)=1,"1st","other dups"),"")
If you want to see the occurrence instead of '1st' and 'other dups', use the following formula in B2 copied down :
=IF(COUNTIF(A:A;A2)>1;COUNTIF(A$2:A2;A2);1)
Example:
The requirement is that column 'A' is sorted.

Resources