+ Reply to Thread
Results 1 to 8 of 8

Names in different formats

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-28-2011
    Location
    Delhi
    MS-Off Ver
    Excel 2007
    Posts
    101

    Names in different formats

    Hi,

    Sharma , Sushil Kant
    Sharma, Sushil Kant
    Sharma ,Sushil Kant
    Sharma , Sushil Kant
    Sushil Kant Sharma

    Assuming last word as last name in the last format, I want all the above names in:

    Sharma, Sushil Kant

    Removing all unnecessary spaces.

    Thanks in advance.

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Names in different formats

    With your sample data in A1:A5
    Sharma , Sushil Kant
    Sharma, Sushil Kant
    Sharma ,Sushil Kant
    Sharma , Sushil Kant
    Sushil Kant Sharma
    This regular formula begins the list of transformations
    B1: =TRIM(IFERROR(MID(A1,FIND(",",A1)+1,LEN(A1))&" "&LEFT(A1,FIND(",",A1)-1),A1))
    Copy that formula down through B5

    These will be the results:
    Sushil Kant Sharma
    Sushil Kant Sharma
    Sushil Kant Sharma
    Sushil Kant Sharma
    Sushil Kant Sharma

    Is that something you can work with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Forum Contributor
    Join Date
    10-28-2011
    Location
    Delhi
    MS-Off Ver
    Excel 2007
    Posts
    101

    Re: Names in different formats

    Sorry to bother you, but as I mentioned above, correct format is: Sharma, Sushil Kant

  4. #4
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,481

    Re: Names in different formats

    Hi Ron, you give "Sushil Kant Sharma" while OP expects "Sharma, Sushil Kant"
    I suggest:
    =IF(ISNUMBER(SEARCH(",",A1)),TRIM(LEFT(SUBSTITUTE(A1,",",REPT(" ",255)),255))&", "&TRIM(RIGHT(SUBSTITUTE(A1,",",REPT(" ",255)),255)),TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",255)),255))&", "&SUBSTITUTE(A1,TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",255)),255)),""))
    Hope this help
    Quang PT

  5. #5
    Forum Contributor
    Join Date
    10-28-2011
    Location
    Delhi
    MS-Off Ver
    Excel 2007
    Posts
    101

    Re: Names in different formats

    Absolutely correct...

    and thanks for your correct formula.

  6. #6
    Forum Contributor
    Join Date
    10-28-2011
    Location
    Delhi
    MS-Off Ver
    Excel 2007
    Posts
    101

    Re: Names in different formats

    Quote Originally Posted by bebo021999 View Post
    Hi Ron, you give "Sushil Kant Sharma" while OP expects "Sharma, Sushil Kant"
    I suggest:
    =IF(ISNUMBER(SEARCH(",",A1)),TRIM(LEFT(SUBSTITUTE(A1,",",REPT(" ",255)),255))&", "&TRIM(RIGHT(SUBSTITUTE(A1,",",REPT(" ",255)),255)),TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",255)),255))&", "&SUBSTITUTE(A1,TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",255)),255)),""))
    Hope this help

    I just want to know why REPT(" ",255) is used.

  7. #7
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,481

    Re: Names in different formats

    Quote Originally Posted by sushil10s View Post
    I just want to know why REPT(" ",255) is used.
    Small example: "Sushil Shama" change to "Shama Sushil"
    You can use SEARCH the position of space betweens 2 words (=7), then use MID(text,7+1,LEN(text)) to get "Shama", then LEFT(text,7-1) to get "Sushil", then concanate both with "&"
    Sometime, there are more words, and have more space inside, while SEARCH space only returns first position of first space (i.e Sushil Kan Shama)
    I usually use REPT(" ",255) to add 255 spaces btw words:
    Sushil ... Shama
    And RIGHT(...,255) always return " Shama", then use TRIM to get "Shama"
    And while 255? Because the max number of characters in cell is 255, so using 255 is in general.
    Hope it is clear for you

  8. #8
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Names in different formats

    You're right...I mis-read the requirements.

    This is the correct formula I should have posted:
    B1: =TRIM(IFERROR(TRIM(LEFT(A1,FIND(",",A1)-1))&", "&MID(A1,FIND(",",A1)+1,LEN(A1)),RIGHT(SUBSTITUTE(A1," ",REPT(" ",LEN(A1))),LEN(A1))&", "&LEFT(
    SUBSTITUTE(A1," ",REPT(" ",LEN(A1))),LEN(A1)*2)))
    And these are the results:
    Sharma, Sushil Kant
    Sharma, Sushil Kant
    Sharma, Sushil Kant
    Sharma, Sushil Kant
    Sharma, Sushil Kant
    Last edited by Ron Coderre; 01-20-2013 at 12:58 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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