+ Reply to Thread
Results 1 to 4 of 4

Strip Leading and Trailing Spaces

  1. #1
    Registered User
    Join Date
    01-12-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, 2003
    Posts
    84

    Strip Leading and Trailing Spaces

    The users in this place are killing me with their fat fingers. It's been such a long time since I wrote code like this so does anyone have a quick snippet which will allow only alphanumeric input and strip any leading and/or trailing spaces from an input field?
    Wish I didn't know now what I didn't know then.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Strip Leading and Trailing Spaces

    Hello Vladamir ,

    Use the Trim function. It will remove all leading and trailing spaces from string. There is a Formula version and VBA version.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  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,917

    Re: Strip Leading and Trailing Spaces

    you could also maybe add data validation to the input cells to reduce/prevent that happeing in the 1st place?
    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
    Registered User
    Join Date
    01-12-2012
    Location
    USA
    MS-Off Ver
    Excel 2007, 2003
    Posts
    84

    Re: Strip Leading and Trailing Spaces

    Thanks. The TRIM function worked like a charm. Even as the string is being concatenated it worked perfectly.

+ 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