+ Reply to Thread
Results 1 to 5 of 5

Name Formatting: Is there a better way to eliminate spaces?

  1. #1
    Registered User
    Join Date
    11-13-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    2

    Question Name Formatting: Is there a better way to eliminate spaces?

    I have the following input and formula:

    In table column "inputLiveOps[Agent Full Name]" I have the following text values:

    "doej (John)" <------------- ideal scenario
    "smithd (Dennis)" <------- extra space between first initial and opening bracket
    "knoxj (Jim )" <------------ extra space between end of first name and closing bracket

    Desired results: Name in format "Last, First".

    Here is my formula:

    'Checks for empty
    =IF(inputLiveOps[@[Agent Full Name]]="","",

    'Gets last name
    PROPER(LEFT(inputLiveOps[@[Agent Full Name]],

    'Checks for extra spaces between first initial and opening bracket
    IF(RIGHT(LEFT(inputLiveOps[@[Agent Full Name]],SEARCH("(",inputLiveOps[@[Agent Full Name]])),3)=" (",

    'Value if true ie extra space
    SEARCH("(",inputLiveOps[@[Agent Full Name]])-4,

    'Value if false ie no extra space
    SEARCH("(",inputLiveOps[@[Agent Full Name]])-3)))

    'add ", " to format name as "Last, First"
    &", "

    'Get first name from between the () brackets
    &MID(inputLiveOps[@[Agent Full Name]],SEARCH("(",inputLiveOps[@[Agent Full Name]])+1,

    'if extra space after first name
    IF(RIGHT(inputLiveOps[@[Agent Full Name]],2)=" )",

    'value is extra space
    SEARCH(")",inputLiveOps[@[Agent Full Name]])-SEARCH("(",inputLiveOps[@[Agent Full Name]])-2,

    'value if no extra space
    SEARCH(")",inputLiveOps[@[Agent Full Name]])-SEARCH("(",inputLiveOps[@[Agent Full Name]])-1)))


    Is there a better way to deal with extra spaces? It seems very clumsy to have two IF statements in the middle of the formula.

    Full formula for pasting:

    Please Login or Register  to view this content.

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Name Formatting: Is there a better way to eliminate spaces?

    I'm kind of partial to SUBSTITUTE, and then concatenating the left and right with a space between.

    =SUBSTITUTE(LEFT(SUBSTITUTE(A1,"(",REPT(" ",100)&"("),100)," ","")&" "&SUBSTITUTE(RIGHT(SUBSTITUTE(A1,"(",REPT(" ",100)&"("),100)," ","")

    The nested substitute finds the first parenthesis, and inserts 100 spaces, left pulls the first 100 characters, and the outside sub removes all spaces.

    It then adds a space, and does the same from the right.

    Adjusted for your references:


    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by daffodil11; 04-02-2014 at 05:57 PM. Reason: ODIN'S RAVEN!
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Name Formatting: Is there a better way to eliminate spaces?

    Hi,

    Does this work for you

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    It assumes you have stuff like
    doej (John) in A2 and down

    I realise you have a table but I much prefer to use cell refs, e.g. A2 here rather than what I think a rather cumbersome approach that you get when you let Excel decide to use a table ref and a column header. Never really understood why MS thought this was superior.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Name Formatting: Is there a better way to eliminate spaces?

    ....sorry small correction

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-13-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Name Formatting: Is there a better way to eliminate spaces?

    Thanks daffodil11 and Richard! I need to start using SUBSTITUTE and LEN - the formula is a lot shorter that way.

+ 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. how i eliminate spaces between cells
    By TORINO7 in forum Excel General
    Replies: 5
    Last Post: 08-15-2018, 09:25 AM
  2. [SOLVED] How do I eliminate spaces/characters from the beginning of a cell
    By Biff in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2005, 12:05 PM
  3. How do I eliminate spaces/characters from the beginning of a cell
    By Biff in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2005, 07:05 AM
  4. How do I eliminate spaces/characters from the beginning of a cell
    By Biff in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-06-2005, 06:05 AM
  5. How do I eliminate spaces/characters from the beginning of a cell
    By A Waller in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM

Tags for this Thread

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