+ Reply to Thread
Results 1 to 6 of 6

Removing Spaces at the Beginning and/or End of a Text String

  1. #1
    Registered User
    Join Date
    02-10-2013
    Location
    PR
    MS-Off Ver
    Excel 2003
    Posts
    93

    Removing Spaces at the Beginning and/or End of a Text String

    I'm working with a table of names and sometimes when I import them I get a space before the name and sometimes a space after the name. Is there a function or some code I can run to check whether the first character and the last character in a cell is a space character, and if any, or both, occur have them removed (the space characters either before or after the name? Thanks!

    Note: Sometimes the data I'm working with imports ' John Doe' and sometimes it imports 'John Doe '. Very rarely I get ' John Doe ', but it has happened. Thanks!

  2. #2
    Forum Expert
    Join Date
    12-11-2011
    Location
    Netherlands
    MS-Off Ver
    office 365
    Posts
    3,293

    Re: Removing Spaces at the Beginning and/or End of a Text String

    You can use the 'TRIM' function
    Willem
    English is not my native language sorry for errors
    Please correct me if I'm completely wrong

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Removing Spaces at the Beginning and/or End of a Text String

    assuming your data is in A1, use this, copied down...
    =TRIM(A1)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Removing Spaces at the Beginning and/or End of a Text String

    self-deleted duplicate post

  5. #5
    Registered User
    Join Date
    02-10-2013
    Location
    PR
    MS-Off Ver
    Excel 2003
    Posts
    93

    Re: Removing Spaces at the Beginning and/or End of a Text String

    Quote Originally Posted by popipipo View Post
    You can use the 'TRIM' function
    That was easy! Thanks!

  6. #6
    Registered User
    Join Date
    02-10-2013
    Location
    PR
    MS-Off Ver
    Excel 2003
    Posts
    93

    Re: Removing Spaces at the Beginning and/or End of a Text String

    Quote Originally Posted by FDibbins View Post
    assuming your data is in A1, use this, copied down...
    =TRIM(A1)
    Beautiful! Thanks!

+ 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