+ Reply to Thread
Results 1 to 8 of 8

Leading or trailing spaces code failing randomly

  1. #1
    Forum Contributor
    Join Date
    06-08-2012
    Location
    Lagos, Nigeria
    MS-Off Ver
    Excel 2007, 2010, 2016
    Posts
    102

    Leading or trailing spaces code failing randomly

    Dear Experts,

    I used the code below in cleaning out "leading or trailing" spaces in any workbook (saw the code on one of the excel forums, cant remember which) that i am working on. However lately, i discovered that it just fails for no reason and some days it will work without issues.

    Can anybody help spot what could be wrong with this code? or help with another code that works.

    Please Login or Register  to view this content.
    Note: The above code cleans out my Sheet(s) instantly and i don't have to loop (I have a big data set). That is why i am partial to it and want it to work

  2. #2
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: Leading or trailing spaces code failing randomly

    What happens when you say the code fails?
    Cheers!
    Deep Dave

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,650

    Re: Leading or trailing spaces code failing randomly

    There is a big chance, that you have some of this spaces being not real spaces (char(32)) but for instance char(160). Clean only deals with first 31 ascii codes.
    See description of CLEAN: https://support.office.com/en-us/art...5-4b8ba987ba41
    may be
    Please Login or Register  to view this content.
    would do
    Best Regards,

    Kaper

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,650

    Re: Leading or trailing spaces code failing randomly

    Or
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    06-08-2012
    Location
    Lagos, Nigeria
    MS-Off Ver
    Excel 2007, 2010, 2016
    Posts
    102

    Re: Leading or trailing spaces code failing randomly

    See attached NeedForExcel

    Capture.JPG

    Note: wksPT is defined as a worksheet..

  6. #6
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,873

    Re: Leading or trailing spaces code failing randomly

    Can you show the full code?

  7. #7
    Forum Contributor
    Join Date
    06-08-2012
    Location
    Lagos, Nigeria
    MS-Off Ver
    Excel 2007, 2010, 2016
    Posts
    102

    Re: Leading or trailing spaces code failing randomly

    Thanks Kaper for the snippets.. They both worked and i like the shorter version better

  8. #8
    Forum Contributor
    Join Date
    06-08-2012
    Location
    Lagos, Nigeria
    MS-Off Ver
    Excel 2007, 2010, 2016
    Posts
    102

    Re: Leading or trailing spaces code failing randomly

    Not really NeedforExcel. However, i will go with Kaper's code and i give Jindon's code a twirl from the link below (Saw the code some mins ago).

    http://www.excelforum.com/excel-prog...ve-spaces.html

    Thanks for your help and time Kaper and NeedForExcel.. Much appreciated!

+ 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] Remove leading and trailing spaces in a cell?
    By LF_CC in forum Excel General
    Replies: 4
    Last Post: 12-05-2013, 03:12 PM
  2. insert leading or trailing spaces
    By 2008 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-05-2013, 08:58 PM
  3. [SOLVED] Removing leading and trailing spaces
    By mangesh in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-18-2013, 05:25 AM
  4. Delete all trailing and leading spaces in multiple .csv files
    By rob_ford16 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-11-2013, 12:51 PM
  5. delete leading trailing and excessive spaces
    By djwaz69 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-28-2012, 03:59 AM
  6. [SOLVED] Strip Leading and Trailing Spaces
    By Vladamir in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-19-2012, 03:46 PM
  7. Deleting leading and trailing spaces from a number
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-31-2009, 11:25 PM
  8. How keep Leading/Trailing spaces when save in Excel?
    By jorgejulio in forum Excel General
    Replies: 0
    Last Post: 08-01-2006, 04:49 PM

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