Extract Names from long String with specific criteria?

jeffcoleky

Active Member
Joined
May 24, 2011
Messages
274
Can someone help me create either a macro or a formula to extract the first 4 names out of each row in column "A". By "Help me create" I mean "Do it for me" because I'm absolutely lost as to where to begin...:confused:

The Raw data is all in column A and I want each name output to Columns B, C, D, E depending on how many are found. Any names after the 4th in any given row are not needed. I'd also like to re-order the name to be "First Last" instead of "LAST, FIRST, MIDDLE".

I've placed examples in this sheet of how I expect it will look when finished. If this request for help is unreasonable let me know and I'll try to find another way around this issue.

DOWNLOAD SAMPLE DATA BELOW HERE

Consistent Facts about the Raw Data (Column A):

  1. If more than one name is contained in the string, each is separated by a semicolon
  2. Name formats are "Last, First, Middle;" or "Last, First;"
  3. Names will always have at least one comma
  4. Company names will have at least one or more spaces separating the words
  5. If a business name is longer than 20 characters long, a ", " is added to the string for each 20 characters

Macro or Formula should Ignore value if any of the following are true:

  1. Charaters (including spaces) exceed 19 characters (because it must be a company name)
  2. String contains "&" (because it must be a company name)
  3. Duplicate to value already gathered from same row
  4. String is after the 3rd semicolon (only need values for the first 4)

-Jeff


Excel 2013
ABCDE
1DESIRED OUTPUT
2
RAW DATA​
Name1Name2Name3Name4
3HART, JENNIFER, R; GENERAL REVENUE INC; COMMONWEALTH OF OHIO DIVIS, ION OF UNEMPLOYMENT, INSURANCEJennifer Hart
4MILLER, JEANNIE, L; MILLER, JEANNIE; MILLER, JOHN, U; MILLER, JOHN; MORTON CENTER; COMMONWEALTH OF OHIO FINAN, CE & ADMINISTRATION, CABINETJeannie MillerJohn Miller
5DELACRUZ, CHRIS; DELACRUZ, CHRIS, BChris Delacruz
6UNITED STATES OF AMERICA SECRE, TARY OF HOUSING & UR, BAN DEVELOPMENT; HARRELL, ESTELLE, C; HARRELL, DORSEY, EEstelle HarrellDorsey Harrell
7RAGAINS, SEBRINA, N; RAGAINS, RICHARD, C; RAGAINS, RICHARD; UNIVERSITY OF UROLOGY PLLC; TIPTON & UNROE PSC; MIDLANE PARK NEIGHBORHOOD ASSN, INCSabrina RagainsRichard RagainsUniversity Of Urology Pllc
8WILCHER, ANTHONY, L; REPUBLIC BANK & TRUST CO
9SIMPSON, JACQUELINE
10LE, SON, VAN; LE, THUYLIEU, THISon LeThi Thuylieu
11SCRUGGS, ALMA, H; SCRUGGS, ALMA, JEAN; CITIFINANCIAL SERVICES INC; COMMERCIAL CREDIT CORP; UNION TRUST INC; ARROWOOD IDEMNITY CO; ROYAL INDEMNITY; CAPITAL ONE BANK USA NA; CAPITAL ONE BANK; ANDERSSON ANDERSSON COUNTY ME, TRO GOVERNMENTAlma Scruggs Citifinancial Services Inc Citifinancial Services Inc
12COLVIN, TODD; COLVIN, ERIC; BANK OF ANDERSSON & TRUST CO; THE ESTATE OF ROBERT WAYNE COLVINTodd ColvinEric Colvin
13KNIGHT, NOLAN, ANolan Knight
14TATE, MARIO, EXR; TATE, MARIO, A EXR; UNITED STATES OF AMERICA SECRE, TARY OF HOUSING & UR, BAN DEVELOPMENT; ANDERSSON ANDERSSON COUNTY ME, TRO DEPARTMENT OF CO, DES & REGULATIONS; CITIMORTGAGE INC; COMMONWEALTH OF OHIO CABIN, ET FOR HUMAN RESOURC, ES DIVISION OF UNEMP; BILARCZYK, NADINEMario Tate
15SMITH, LORA, A; SMITH, LORA, ASHLEY; SMITH, ASHLEY; PROVIDIAN NATIONAL BANK; SMITH, JOSEPH; SMITH, JOSEPH, JR; SMITH, JOSEPH, L JR; BROWN, MICHAEL; NATIONAL CITY REAL ESTATE SERV, ICES LLC; NATIONAL CITY MORTGAGE CO; ARROW FINANCIAL SERVICES LLC; OEM COATINGS; AUTOVEST LLC; SMITH, MARTHA, EXR; ANDERSSON ANDERSSON COUNTY ME, TRO GOVERNMENT; CNAC; COMMONWEALTH OF OHIO WORKF, ORCE DEVELOPMENT CAB, INET EX REL DIVISION; EQUITABLE FINANCIAL SERVICES L, LC; CAPITAL ONE BANK USA NA; CAPITAL ONE BANK; ALBAN USED CARS I LLC; ALBAN USED CARS INC; FIRST RESOLUTION INVESTMENT CO, RP; COMMONWEALTH OF OHIO FINAN, CE & ADMINISTRATION, CABINET; BBC CHECK ADVANCE LLC; UNITED STATES OF AMERICA DEPAR, TMENT OF THE TREASUR, Y INTERNAL REVENUE S; NORTON HEALTHCARE INC; REPUBLIC BANK & TRUST CO; ECKART LLC; STONE CREEK FINANCIAL; ANDERSSON ANDERSSON COUNTY ME, TRO REVENUE COMMISSI, ONLora SmithAshley Smith
16FOREE, MICHAEL, W JR; FOREE, MICHAEL, JR; FOREE, DEMITRIA, V; FOREE, DEMETRIA, V; FOREE, DEMITRIA; NORTON AUDUBON HOSPITAL; NORTON HEALTHCARE INC; DR GREGORY CECIL DMD LLC; ANDERSSON ANDERSSON COUNTY ME, TRO DEPARTMENT OF IN, SPECTIONS PERMITS &Michael ForeeDemitria Foree
17TRAN, NGOC; LE, HAJ, P; LE, HAI, PNgoc TranHaj Le
18DEWALT, DAVID, J; DEWALT, KESHA, R; CHEMICAL MORTGAGE CODavid DewaltKesha DewaltMortgage Chemical
19ABERNATHY, VELDA, J; COLVIN, WILMA, M; ABERNATHY, WILMA, M; TRILOGY HEALTHCARE OF JEFFERSO, N LLC; FRANCISCAN HEALTH CARE CENTERVelda AbernathyWilma ColvinWilma Abernathy
20ZACHARY, REGINA, C; B&B FUNDING LLCRegina Zachary
21FRENCH, STENNIS; FRENCH, REGINA; NATIONAL CITY MORTGAGE CO; SECRETARY OF HOUSING & URBAN D, EVELOPMENT; HOUSEHOLD FINANCE CORP II; CAPITAL ONE BANKStennis FrenchRegina French
22CRAIG, JOHN, P JR; BLACK, LINDA; OHIO HOUSING CORPJohn CraigLinda Black
23CLAY, PAUL; CLAY, PAUL, EUGENE III; CLAY, NANCY, GPaul ClayNancy Clay
24BREWER, CRAIG, L; BREWER, DONNA; BREYER, DONNA, Y; ANDERSSON ANDERSSON COUNTY ME, TRO GOVERNMENT; ANDERSSON ANDERSSON COUNTY ME, TRO DEPARTMENT OF CO, DES & REGULATIONS; CLINICAL PATHOLOGY ASSOCIATES, INC; CPA LABS; BARDSTOWN IMMEDIATE CARE CENTE, RCraig BrewerDonna Brewer
25CRAWFORD, ROY; CRAWFORD, TRESSA; COMMONWEALTH OF OHIO EDUCA, TION CABINET EX REL, DIVISION OF UNEMPLOY; BILLTOWN FARM HOMEOWNERS ASSN, INC; DEUTSCHE BANK NATIONAL TRUST C, O, TR; FIRST FRANKLIN MORTGAGE LOAN T, RUST, TRRoy CrawfordTressa Crawford

<tbody>
</tbody>
Sheet1
 
I don't understand why you question this one? It's the first name in row 14, why would it not be used? (In this instance, "Exr" Stands for "executor" as in "executor of an estate". So it's still a name we want)

"TATE, MARIO, EXR; TATE, MARIO, A EXR; UNITED STATES OF AMERICA SECRE, TARY OF HOUSING & UR, BAN DEVELOPMENT; ANDERSSON ANDERSSON COUNTY ME, TRO DEPARTMENT OF CO, DES & REGULATIONS; CITIMORTGAGE INC; COMMONWEALTH OF OHIO CABIN, ET FOR HUMAN RESOURC, ES DIVISION OF UNEMP; BILARCZYK, NADINE"
My fault... I turned word wrap on and then shrunk the width of Column A and changed the height to show two rows thinking that was enough, but Row 14 is three lines high and I didn't see the first line of it.

However, while I am looking at Row 14, just double checking... the name at the end doesn't show because it is past the 4th semi-colon? Or is it that once you get a company name, you stop looking?
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
My fault... I turned word wrap on and then shrunk the width of Column A and changed the height to show two rows thinking that was enough, but Row 14 is three lines high and I didn't see the first line of it.

However, while I am looking at Row 14, just double checking... the name at the end doesn't show because it is past the 4th semi-colon? Or is it that once you get a company name, you stop looking?

Sometimes a company will be the leading entry so we can't exclude everything after the first company name or we exclude the important names. Thus the 4th semicolon is the rule.
 
Upvote 0
Sometimes a company will be the leading entry so we can't exclude everything after the first company name or we exclude the important names. Thus the 4th semicolon is the rule.
See if this macro does what you want...

Code:
Sub GetNamesFromData()
  Dim R As Long, C As Long, X As Long, Z As Long, IsThere As Long
  Dim Data As Variant, Results As Variant
  Dim Temp As String, Txt() As String, S() As String
  Data = Range("A3", Cells(Rows.Count, "A").End(xlUp))
  ReDim Results(1 To UBound(Data), 1 To 4)
  For R = 1 To UBound(Data)
    C = 0
    Txt = Split(Data(R, 1) & ";;;;", ";")
    For X = 0 To 3
      If Txt(X) Like "*, *" And Not Txt(X) Like "*[!,] *" Then
        C = C + 1
        IsThere = 0
        S = Split(Txt(X) & ", , ", ", ")
        Temp = Trim(S(1)) & " " & Trim(S(0))
        For Z = 1 To C - 1
          If Results(R, Z) = Temp Then IsThere = 1
        Next
        If IsThere = 0 Then
          Results(R, C) = StrConv(Temp, vbProperCase)
        Else
          C = C - 1
        End If
      End If
    Next
  Next
  Range("B3").Resize(UBound(Results), 4) = Results
End Sub

NOTE: Your output for Row 16 shows two names ("Michael Foree" and "Demitria Foree"), but my code shows three names... the second name is in there twice, but the first name is spelled differently... I cannot think of a way to make the code decide these are the same name without having a "dictionary" of all the possible misspellings of all the possible names.
 
Upvote 0
See if this macro does what you want...

Code:
Sub GetNamesFromData()
  Dim R As Long, C As Long, X As Long, Z As Long, IsThere As Long
  Dim Data As Variant, Results As Variant
  Dim Temp As String, Txt() As String, S() As String
  Data = Range("A3", Cells(Rows.Count, "A").End(xlUp))
  ReDim Results(1 To UBound(Data), 1 To 4)
  For R = 1 To UBound(Data)
    C = 0
    Txt = Split(Data(R, 1) & ";;;;", ";")
    For X = 0 To 3
      If Txt(X) Like "*, *" And Not Txt(X) Like "*[!,] *" Then
        C = C + 1
        IsThere = 0
        S = Split(Txt(X) & ", , ", ", ")
        Temp = Trim(S(1)) & " " & Trim(S(0))
        For Z = 1 To C - 1
          If Results(R, Z) = Temp Then IsThere = 1
        Next
        If IsThere = 0 Then
          Results(R, C) = StrConv(Temp, vbProperCase)
        Else
          C = C - 1
        End If
      End If
    Next
  Next
  Range("B3").Resize(UBound(Results), 4) = Results
End Sub

Wowzers! it worked! Yay. Thanks so much for that help! Having both names come up with a small typo is a good thing actually. thanks again! I could have never done it without your help.
 
Upvote 0

Forum statistics

Threads
1,215,231
Messages
6,123,754
Members
449,119
Latest member
moudenourd

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top