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
HART, JENNIFER, R; GENERAL REVENUE INC; COMMONWEALTH OF OHIO DIVIS, ION OF UNEMPLOYMENT, INSURANCEJennifer Hart
MILLER, JEANNIE, L; MILLER, JEANNIE; MILLER, JOHN, U; MILLER, JOHN; MORTON CENTER; COMMONWEALTH OF OHIO FINAN, CE & ADMINISTRATION, CABINETJeannie MillerJohn Miller
DELACRUZ, CHRIS; DELACRUZ, CHRIS, BChris Delacruz
UNITED STATES OF AMERICA SECRE, TARY OF HOUSING & UR, BAN DEVELOPMENT; HARRELL, ESTELLE, C; HARRELL, DORSEY, EEstelle HarrellDorsey Harrell
RAGAINS, SEBRINA, N; RAGAINS, RICHARD, C; RAGAINS, RICHARD; UNIVERSITY OF UROLOGY PLLC; TIPTON & UNROE PSC; MIDLANE PARK NEIGHBORHOOD ASSN, INCSabrina RagainsRichard RagainsUniversity Of Urology Pllc
WILCHER, ANTHONY, L; REPUBLIC BANK & TRUST CO
SIMPSON, JACQUELINE
LE, SON, VAN; LE, THUYLIEU, THISon LeThi Thuylieu
SCRUGGS, 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
COLVIN, TODD; COLVIN, ERIC; BANK OF ANDERSSON & TRUST CO; THE ESTATE OF ROBERT WAYNE COLVINTodd ColvinEric Colvin
KNIGHT, NOLAN, ANolan Knight
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, NADINEMario Tate
SMITH, 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
FOREE, 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
TRAN, NGOC; LE, HAJ, P; LE, HAI, PNgoc TranHaj Le
DEWALT, DAVID, J; DEWALT, KESHA, R; CHEMICAL MORTGAGE CODavid DewaltKesha DewaltMortgage Chemical
ABERNATHY, VELDA, J; COLVIN, WILMA, M; ABERNATHY, WILMA, M; TRILOGY HEALTHCARE OF JEFFERSO, N LLC; FRANCISCAN HEALTH CARE CENTERVelda AbernathyWilma ColvinWilma Abernathy
ZACHARY, REGINA, C; B&B FUNDING LLCRegina Zachary
FRENCH, STENNIS; FRENCH, REGINA; NATIONAL CITY MORTGAGE CO; SECRETARY OF HOUSING & URBAN D, EVELOPMENT; HOUSEHOLD FINANCE CORP II; CAPITAL ONE BANKStennis FrenchRegina French
CRAIG, JOHN, P JR; BLACK, LINDA; OHIO HOUSING CORPJohn CraigLinda Black
CLAY, PAUL; CLAY, PAUL, EUGENE III; CLAY, NANCY, GPaul ClayNancy Clay
BREWER, 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
CRAWFORD, 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>
[TD="align: center"]1[/TD]
[TD="align: center"][/TD]
[TD="align: center"] DESIRED OUTPUT [/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]

[TD="align: center"]2[/TD]
[TD="align: center"]
RAW DATA​
[/TD]
[TD="bgcolor: #E2EFDA, align: center"]Name1[/TD]
[TD="bgcolor: #E2EFDA, align: center"]Name2[/TD]
[TD="bgcolor: #E2EFDA, align: center"]Name3[/TD]
[TD="bgcolor: #E2EFDA, align: center"]Name4[/TD]

[TD="align: center"]3[/TD]

[TD="align: center"]4[/TD]

[TD="align: center"]5[/TD]

[TD="align: center"]6[/TD]

[TD="align: center"]7[/TD]

[TD="align: center"]8[/TD]

[TD="align: center"]9[/TD]

[TD="align: center"]10[/TD]

[TD="align: center"]11[/TD]

[TD="align: center"]12[/TD]

[TD="align: center"]13[/TD]

[TD="align: center"]14[/TD]

[TD="align: center"]15[/TD]

[TD="align: center"]16[/TD]

[TD="align: center"]17[/TD]

[TD="align: center"]18[/TD]

[TD="align: center"]19[/TD]

[TD="align: center"]20[/TD]

[TD="align: center"]21[/TD]

[TD="align: center"]22[/TD]

[TD="align: center"]23[/TD]

[TD="align: center"]24[/TD]

[TD="align: center"]25[/TD]

</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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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