+ Reply to Thread
Results 1 to 6 of 6

Removing a leading space in VB script

  1. #1
    Registered User
    Join Date
    08-16-2012
    Location
    Edinburgh
    MS-Off Ver
    Excel 2003
    Posts
    3

    Removing a leading space in VB script

    Hi all,

    I have a single column of data in which every cell is preceded by a space. I need to get rid of the space before the data can be properly handled by the rest of my scripts and counted correctly.

    I can do this already within Excel using this line below in each cell's adjacent cell -

    Please Login or Register  to view this content.
    Trouble is, this looks really messy, since it requires having two columns featuring basically the same data, albeit column A with the original data (eg. " 1234") and column B with the presentable data (eg. "1234", no space).

    What I'd like to do would be run a line of code that does the same preceding space-removing magic as the IF command above, but do it within the macro rather than within cells on the page.

    If anyone can suggest anything, it'd be very much appreciated.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Removing a leading space in VB script

    Something like
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    08-16-2012
    Location
    Edinburgh
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Removing a leading space in VB script

    Sorry if this is a double-post. I think IE (I know...) ate the previous one.

    Anyways, thanks for that, Mike. It works, but not quite as I need it to. The problem is, it's removing the leading space from a text cell fine, but it ignores cells that only have a number in them. So, " Module" becomes "Module", but " 3" remains as " 3", where I need it to become "3". Any suggestions there?

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

    Re: Removing a leading space in VB script

    Try
    Please Login or Register  to view this content.

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Removing a leading space in VB script

    Quote Originally Posted by FkRndmLttrs View Post
    Sorry if this is a double-post. I think IE (I know...) ate the previous one.

    Anyways, thanks for that, Mike. It works, but not quite as I need it to. The problem is, it's removing the leading space from a text cell fine, but it ignores cells that only have a number in them. So, " Module" becomes "Module", but " 3" remains as " 3", where I need it to become "3". Any suggestions there?
    I can't duplicate that error, could you post a workbook with some of those recalcitrant " 3" entry's

  6. #6
    Registered User
    Join Date
    08-16-2012
    Location
    Edinburgh
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Removing a leading space in VB script

    Thanks guys. I'll let you know how it goes when I get home.

+ 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