Formula to reformat of names in excel where column A has Last, First, Middle but not always a middle - excel

I have a column of names (column A) formatted as "Last, First, Full Middle".
However, some of the names in column A do not have a middle name (i.e. only have "Last, First" or "Last, First, Middle initial"). I'm trying to come up with a formula (or multiple) that formats the names so that column B has "Last, First, Middle initial[period]" and column C has "Last, First Middle initial[period]"
E.g., if column A has: Smith, John, David
then I want column B to be: Smith, John, D.
and column C to be: Smith, John D.
I tried the following:
in column B:
=IF(ISBLANK(A2),"",LEFT(A2,FIND("~",SUBSTITUTE(A2," ","~",LEN(A2)-LEN(SUBSTITUTE(A2," ",""))))+1)&".")
and in column c:
=IF(ISBLANK(A2),"",SUBSTITUTE(B2,", "," ",LEN(B2)-LEN(SUBSTITUTE(B2," ",""))))
Both formulas work EXCEPT if the name in column A doesn't have a middle name.

Use this in Column B:
=IFERROR(LEFT(A1,FIND("~",SUBSTITUTE(A1,",","~",2))+1)&MID(A1,FIND("~",SUBSTITUTE(A1,",","~",2))+2,1)&".",A1)
and in Column C:
=IFERROR(LEFT(A1,FIND("~",SUBSTITUTE(A1,",","~",2))-1)&" "&MID(A1,FIND("~",SUBSTITUTE(A1,",","~",2))+2,1)&".",A1)

Related

Excel - Extracting substring after a character contained in a string

I am trying to extract partial string contained within a cell after a certain character in the string.
I have a formula which can do this
=RIGHT(C10,LEN(C10)-SEARCH(":",C10))
But let's say the location of C10 cell isn't exactly known within the C column, and a way to locate it is by searching for a keyword in column D and then extracting the partial string using the above formula to a cell next to the keyword (column E).
I hope this makes sense.
Ex)
Column C
John: 1234 Alphabet Street
Claire: 3456 Diamond Street
Tim: 333 Laugh Lane
Bo: 5555 Great Neck Street
Grace: 777 Whiteside Blvd
Column D
John:
Claire:
Bo:
Thank you.
You could use:
=TRIM(SUBSTITUTE(VLOOKUP(D1&"*",C:C,1,0),D1,""))
This approach should work for you. First, modify the formula as below for the first row in E (i.e., E2)
=IF(ISTEXT(D2),RIGHT(C2,LEN(C2)-SEARCH(":",C2)),"No address found.")
In order to apply this formula throughout for the column triplets C, D and E do the following: Click on the top-left corner of column 'C', hold and drag the cursor towards right to include columns D and E and now drag all the way down to the last row of C, D and E. Now, the formula is automatically applied to all the rows viz. C, D and E.

Splitting addresses into columns in Excel

I need help splitting addresses into columns in Excel.
Addresses in COLUMN A are written like:
601 W Houston St Abbott, TX 76621 United States
13498 US 301 South Riverview, FL 33578 United States
COLUMN B is actually a helper column. It contains only the city names from COLUMN A. My idea was to somehow match COLUMN B with COLUMN A and then all matches move to another column. That would separate City from the Address.State, Zip and Country I can use "split text to columns" since "comma" is delimiter. But I need help splitting address and the city.
There is a "comma" right after the city name, but some cities has more than one word in city name.
What I need to do is split the addresses like it's highlighted in green in the image below.
What is the best way to do that in Excel? What would be the formula for that?
We can use a quirk of LOOKUP to get this working.
=LOOKUP(1E+99,FIND(B$2:B$100,A2),B$2:B$100) in D2 will return the city based on searching for matches in column B. Note that this will need the full range of column B specified to be filled.
Then we can put =LEFT(A2,FIND(D2,A2)-2) in C2 to get the first part of the address.
The rest is easy if we can assume that the state, Zip and country are of constant length (if you've got any addressses outside the US then you'll need to alter this):
=LEFT(RIGHT(A2,22),3) in E2
=LEFT(RIGHT(A2,19),5) in F2
=RIGHT(A2,13) in G2
Since you already have City in Col B, just replace the city in A
D2 =SUBSTITUTE(A2,C2,"")
Column C Paste special values in Col C
Split Column C using comma.
Then split the Column D using "space". Assuming you have all records in US, you can add the country to all rows if required.
EDIT
I missed that the city name in the row does not correspond to the address. To match the city from the Master, you can use this array formula:
C2 =INDEX(B:B,MATCH(1,MATCH(""&$B:$B&"",A2,0),0))
Array formula must be confirmed with Ctrl-Shift-Enter.
However, this will find the first match. If you have cities Foster & Foster City in your master, Foster City wlll never be matched. So, sort the cities in descending order of length.
Once you have the City name matched you can follow the steps I gave earlier. Note that I have adjusted the formula to take into account the city name that has been matched by this new formula.
So, it is possible to get it done with the formula. It may not be the best way, but I got what I needed.
I've added a new sheet and named it "cities"
I moved the city list from sheet 1 to COL A in sheet "cities"
In sheet 1, B1 = =INDEX(cities!$A$1:$A$10000;LOOKUP(99^99;MATCH(RIGHT(TRIM(LEFT(SUBSTITUTE(A2;",";REPT(" ";255));255));ROW($A$1:$A$100));cities!$A$1:$A$10000;0)))
Then I've simply use SUBSTITUTE to remove city names from column A in Sheet 1: C1==SUBSTITUTE(A1, B1, "")
And that's it!

Column A numbers matched with Column B numbers that are assigned to Column C =column D?

This is my example
Column A are numbers
Column B are numbers
Column C are Names
The A column are numbers associated with a item sold to one place. Column B is the items sold and C is the person who sold them. I would like column D to show the item sold to this one place and who sold it. Let me know if that makes sense.
PS: Column A has 1304 rows. Column B and C have 6154 rows
It is hard to guess what your data looks like, so assuming your data looks as below:
Here is my solution, I think it is a simple VLOOKUP problem:
Paste this =IF(ISERROR(VLOOKUP(C2,$A$2:$A$4,1,FALSE)),"","SoldToPlaceA") to E2 and drag it down to copy.

Add cell string to another cell if 2 cells are the same for 2 rows

I'm trying to make a macro that will go through a spreadsheet, and based on the first and last name being the same for 2 rows, add the contents of an ethnicity column to the first row.
eg.
FirstN|LastN |Ethnicity |ID |
Sally |Smith |Caucasian |55555 |
Sally |Smith |Native American | |
Sally |Smith |Black/African American | |
(after the macro runs)
Sally |Smith |Caucasian/Native American/Black/African American|55555 |
Any suggestions on how to do this? I read several different methods for VBA but have gotten confused as to what way would work to create this macro.
EDIT
There may be more than 2 rows that need to be combined, and the lower row(s) need to be deleted or removed some how.
If you can use a formula, then you can do those:
Couple of assumptions I'm making:
Sally is in cell A2 (there are headers in row 1).
No person has more than 2 ethnicities.
Now, for the steps:
Put a filter and sort by name and surname. This provides for any person having their names separated. (i.e. if there is a 'Sally Smith' at the top, there are no more 'Sally Smith' somewhere down in the sheet after different people).
In column D, put the formula =if(and(A2=A3,B2=B3),C2&"/"&C3,"")
Extend the filter to column D and filter out all the blanks.
That is does is it sees whether the names cells A2 and A3 are equal (names are the same), and whether the cells B2 and B3 are equal (surnames are the same).
If both are true, it's the same person, so we concatenate (using & is another way to concatenate besides using concatenate()) the two ethnicities.
Otherwise, if either the name, or username, or both are different, leave as blank.
To delete the redundant rows altogether, copy/paste values on column D, filter on the blank cells in column D and delete. Sort afterwards.
EDIT: As per edit of question:
The new steps:
Put a filter and sort by name and surname. (already explained above)
In column E, put the formula =IF(AND(A1=A2,B1=B2),E1&"/"&C2,C2) (I changed the formula to adapt to the new method)
In column F, put the formula =if(and(A1=A2,B1=B2),F1+1,1)
In column G, put the formula =if(F3<F2,1,0)
In column H, put the formula =if(and(D2="",A1=A2,B1=B2),H1,D2) (this takes the ID wherever it goes).
Put the formulae as from row 2. What step 3 does is putting an incremental number for the people with same name.
What step 4 does is checking for when the column F goes back to 1. This will identify your 'final rows to be kept'.
Here's my output from those formulae:
The green rows are what you keep (notice that there is 1 in column G that allows you to quickly spot them), and the columns A, B, C, E and H are the columns you keep in the final sheet. Don't forget to copy/paste values once you are done with the formulae and before deleting rows!
If first Sally is in A1 then =IF(AND(A1=A2,B1=B2),C1&"/"&C2,"")copied down as appropriate might suit. Assumes where not the same a blank ("") is preferred to repetition of the C value.

Excel Macro - Find a specified value in one column and replace with all the contents of another column(the length is flexible)

I have a spreadsheet with more than 3000 rows, and I want to replace specific values(v1,v2,...) in column A with the content in column B and C and ...
The length of content in column B,C,... is not fixed so it is not possible to use REPLACE function provided in Excel.
It is also impossible to edit for each row, as the content is very long.
simple example:
column A
{who} is the coach of {team}
{who} is the coach of {team}
{who} is the coach of {team}
column B
Alex Ferguson
Roberto Mancini
Rafael Benitez
column C
Man United
Man City
Chelsea
column D
Alex Ferguson is the coach of Man United
Roberto Mancini is the coach of Man City
Rafael Benitez is the coach of Chelsea
Column D is what I want(column B to replace {who}, column c to replace {team}).
Try this in column D:
=SUBSTITUTE(SUBSTITUTE(A1,"{who}",B1),"{team}",C1)
You can also do it without the "{who}" thing in column A:
=B1 & " is the coach of " & C1

Resources