+ Reply to Thread
Results 1 to 6 of 6

Macro to remove leading Spaces

  1. #1
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2024
    Posts
    2,873

    Macro to remove leading Spaces

    I have the following macro to remove leading spaces, but for some unknown reason this is not working on this sample data

    I would like the leading spaces removed so values can be formatted with comma sperators


    it would be appreciated if someone could assist me


    Please Login or Register  to view this content.

    See sample Data attached
    Attached Files Attached Files

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Macro to remove leading Spaces

    Add line to loop to remove LineFeed character

    Please Login or Register  to view this content.
    If you look at the cell you will see that it is not spaces but a new line
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,475

    Re: Macro to remove leading Spaces

    Your "leading space" is not a space character... it is a Line Feed character. Change this line of code...

    dataSet(rw, col) = Trim(dataSet(rw, col))

    to this...

    dataSet(rw, col) = Trim(Replace(dataSet(rw, col), vbLf, ""))

    NOTE: I kept the Trim function call just in case you have some text which really has a leading space in it.

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Macro to remove leading Spaces

    You have hidden character
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2024
    Posts
    2,873

    Re: Macro to remove leading Spaces

    Many Thanks Andy & Ricky for your help and input

    Code works perfectly

  6. #6
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,475

    Re: Macro to remove leading Spaces

    Quote Originally Posted by Howardc1001 View Post
    Many Thanks Andy & Ricky for your help and input
    What about the code jindon posted? It should do what you want (and possibly a little more) all without using a loop.

+ 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. [SOLVED] trim does not remove leading spaces?
    By inventorgeorge in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 05-06-2024, 09:38 PM
  2. [SOLVED] Macro remove leading spaces
    By hftechno in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-30-2018, 09:47 AM
  3. How to remove leading spaces
    By Terressa in forum Excel General
    Replies: 4
    Last Post: 06-27-2015, 07:45 PM
  4. How to Remove Leading Spaces in excel
    By kisanvikas2015 in forum Excel General
    Replies: 5
    Last Post: 05-21-2015, 09:40 AM
  5. Remove Leading Spaces
    By edwardpestian in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-22-2006, 10:34 AM
  6. VBA help please - remove leading spaces
    By Scott Wagner in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-24-2006, 04:20 PM
  7. Remove Leading Spaces
    By Kirk P. in forum Excel General
    Replies: 6
    Last Post: 03-09-2005, 12:10 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