+ Reply to Thread
Results 1 to 11 of 11

TRIM function and leading spaces

  1. #1
    Forum Contributor
    Join Date
    08-22-2005
    Location
    Denmark
    MS-Off Ver
    Excel 365
    Posts
    349

    TRIM function and leading spaces

    I have some cells containing imported text with a lot of leading spaces. I try to get rid of them by TRIM'ing those cells, but it doesn't work.
    Is TRIM only for trailing spaces?



    /NSV
    Last edited by nsv; 10-06-2008 at 10:08 AM.

  2. #2
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264
    No, trimming will work on leading spaces too. The fact that it isn't getting rid of your 'spaces' suggests to me they aren't actually spaces. Try Substitute:

    =SUBSTITUTE(A1,CHAR(160),"")

    CHAR(160) is the non-breaking space character, often confused with an actual space.

    Richard

  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320
    you could also try the =clean() function

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,472
    In my test CLEAN does not removes non-breaking space.
    Cheers
    Andy
    www.andypope.info

  5. #5
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320
    =clean(SUBSTITUTE(A1,CHAR(160),"")) should just about cover every thing then!
    or find /replace alt+160 with nothing

  6. #6
    Forum Contributor
    Join Date
    08-22-2005
    Location
    Denmark
    MS-Off Ver
    Excel 365
    Posts
    349
    The SUBSTITUTE works, thank you very much; I'm impressed that you could guess that the culprit was CHAR(160) :-)

    /NSV
    Last edited by nsv; 09-26-2008 at 03:14 AM.

  7. #7
    Forum Contributor
    Join Date
    08-22-2005
    Location
    Denmark
    MS-Off Ver
    Excel 365
    Posts
    349
    Well, it did work in my first trial, but second time it didn't.
    I then tried CLEAN(SUBSTITUTE(A1,CHAR(160),"")), which also didn't work, but TRIM(SUBSTITUTE(A1,CHAR(160),"")) did the job.
    I can't figure out what is happening, but I suppose I will - eventually. Anyway, thanks a lot for the tips about CLEAN and SUBSTITUTE; I wasn't aware of those functions.

    /NSV

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,472
    Order of operation is important.

    TRIM removes leading/trailing and double spaces, CHAR(32)
    SUBSTITUTE remove non-breaking spaces, CHAR(160)
    CLEAN would remove non-printable characters
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    10-01-2014
    Location
    Wisconsin
    MS-Off Ver
    Excel 2007
    Posts
    1

    Angry Re: TRIM function and leading spaces

    None of normal Trim formulas work in Win 8....excel 2007
    Also f4 does not do normal absolute function

  10. #10
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,779

    Re: TRIM function and leading spaces

    canll,
    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    Ben Van Johnson

  11. #11
    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
    53,006

    Re: TRIM function and leading spaces

    Agree completely with protonLeah, but just wanted to add that all trim functions as well as F4 do work perfectly fine in Win8 MS 2007...that is the config I am running right now
    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

+ 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. Remove leading zeros from a function
    By elbmag in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-19-2007, 01:27 AM
  2. User-defined Function question
    By Chief Wiggums in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-05-2007, 11:34 PM
  3. How to add leading zeros
    By punter in forum Excel General
    Replies: 5
    Last Post: 01-16-2007, 04:56 AM

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