+ Reply to Thread
Results 1 to 8 of 8

Need to add a comma in between Last and First name, but only in some fields

  1. #1
    Registered User
    Join Date
    03-16-2012
    Location
    MN
    MS-Off Ver
    Excel 2010
    Posts
    50

    Need to add a comma in between Last and First name, but only in some fields

    I have an inconsistent field that I need to clean up so I can parse it. The data looks like this:

    Smith, Joan
    Jones Penny L
    Hawkins, Wilma A
    Alexander Byron

    Is there a function that can examine each field, check for a comma before the first space and 1: If the comma is there just return the existing value and 2: if the comma is not there add the comma and return the value with the comma inserted?

  2. #2
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Need to add a comma in between Last and First name, but only in some fields

    Try

    =SUBSTITUTE(SUBSTITUTE(A1,",","")," ",", ",1)

  3. #3
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Need to add a comma in between Last and First name, but only in some fields

    I'd use a small UDF:
    Please Login or Register  to view this content.
    Use as:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  4. #4
    Registered User
    Join Date
    10-29-2014
    Location
    Portland, OR
    MS-Off Ver
    MS Office 2013
    Posts
    54

    Re: Need to add a comma in between Last and First name, but only in some fields

    So it seems like you just need all names to have the LastName comma FirstName. If you're trying to do that I'd just go with a work around using Find/Replace.
    First I'd click on your column of names>open up Find/Replace (Ctrl+F)>type in a space ( ) in "find what">type in a comma then a space (, ) in "replace">this will fix all of the names that don't have commas and put them in there... but now you'll have names with two commas in them... easy fix... click your name column again>Find/Replace (Ctrl+F)>in "find what" type in two commas (,,)>in "replace" type in just one comma (,). This will replace all the double commas and your final outcome will be ALL names on your list will be "LastName, FirstName ".
    It's an unorthodox solution but that's just the way my mind thinks. Hope this helps!

    Kind Regards,

    Tommy Bailey
    Show appreciation by clicking "Add Reputation"

  5. #5
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,063

    Re: Need to add a comma in between Last and First name, but only in some fields

    Yet another way!!

    =IF(MID(A1,FIND(" ",A1)-1,1)=",",A1,SUBSTITUTE(A1," ",", ",1))
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  6. #6
    Registered User
    Join Date
    03-16-2012
    Location
    MN
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Need to add a comma in between Last and First name, but only in some fields

    Quote Originally Posted by Jonmo1 View Post
    Try

    =SUBSTITUTE(SUBSTITUTE(A1,",","")," ",", ",1)
    LOVE IT!
    (I tried to add a reputation but apparently I've been propping you too much lately!)

  7. #7
    Registered User
    Join Date
    03-16-2012
    Location
    MN
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Need to add a comma in between Last and First name, but only in some fields

    Apparently I need to study up on my SUBSTITUTE.

  8. #8
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Need to add a comma in between Last and First name, but only in some fields

    Glad it worked out for you

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Breaking out Comma Delimited Fields - VBA Error - "Subscript out of Range"
    By sev979 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-13-2014, 09:55 AM
  2. [SOLVED] CSV file with a comma in some text fields how to import
    By etaf in forum Access Tables & Databases
    Replies: 4
    Last Post: 09-12-2013, 10:54 PM
  3. [SOLVED] Splitting a comma seperated name into two fields
    By heathb in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-08-2013, 10:27 AM
  4. Find and remove all text to the left of last comma (including comma) in a cell
    By Excelrookie_1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-05-2013, 08:47 AM
  5. [SOLVED] If comma present, then place a character before and after comma (FORMULA)
    By jaimealvarez in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-21-2012, 04:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1