+ Reply to Thread
Results 1 to 5 of 5

Delete Trailing Spaces without Removing leading zeros WITHOUT TRIM

  1. #1
    Registered User
    Join Date
    05-22-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2007
    Posts
    15

    Delete Trailing Spaces without Removing leading zeros WITHOUT TRIM

    OK here is my problem. I am designing a tool for my company that all the user has to do it dump in data and many pages do various things based off the data. Everything is working perfect except I realized the data the user is dumping in has trailing spaces in column A and G. I've dealt with this problem before so I created a quick button with the vba macro attached

    Please Login or Register  to view this content.
    The column G removal of spaces works perfectly. Howver the column A has data that has leading zeros (i.e. 0000345). So when I run this macro the data returns without spaces but for some reason also returns without my leading zeros (i.e. 345). How can I modify this so it keeps my leading zeros intact. Thanks

  2. #2
    Registered User
    Join Date
    05-22-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Delete Trailing Spaces without Removing leading zeros WITHOUT TRIM

    I could use the TRIM function in vba instead but i don't think I can use it in the spreadsheet as =TRIM(A1) because the are entering new data into the spreadsheet everytime

  3. #3
    Registered User
    Join Date
    05-22-2013
    Location
    Indiana
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Delete Trailing Spaces without Removing leading zeros WITHOUT TRIM

    I suppose one thing I could do is put the trim function in another tab and hide that tab but that would require that I change all my cell references in other tabs...

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Delete Trailing Spaces without Removing leading zeros WITHOUT TRIM

    Please Login or Register  to view this content.
    try this
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  5. #5
    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: Delete Trailing Spaces without Removing leading zeros WITHOUT TRIM

    Hello Zach51215,

    VBA has three methods of removing spaces: LTrim, RTrim, Trim

    LTrim removes leading spaces.
    RTrim removes trailing spaces.
    Trim removes both Leading and Trailing spaces.

    You could use this macro to do the job.
    Please Login or Register  to view this content.
    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!)

+ 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