+ Reply to Thread
Results 1 to 7 of 7

VBA help please - remove leading spaces

  1. #1
    Scott Wagner
    Guest

    VBA help please - remove leading spaces

    In column D of my worksheet some of the cell contents have a varying number
    of spaces. How can I removed any leading spaces from those cells with VBA?

    There are spaces within the cells (not leading) that I want to keep.

    Example below.

    Here is what I have now:

    ColD
    This is the text
    Blah Blah Blah
    Blah Blah Blah Blah
    This is the text

    Here is what I'd like to end up with:

    ColD
    This is the text
    Blah Blah Blah
    Blah Blah Blah Blah
    This is the text

    Thanks in advance!

    Scott

  2. #2
    Forum Contributor funkymonkUK's Avatar
    Join Date
    01-07-2005
    Location
    London, England
    Posts
    500
    Quote Originally Posted by Scott Wagner
    In column D of my worksheet some of the cell contents have a varying number
    of spaces. How can I removed any leading spaces from those cells with VBA?

    There are spaces within the cells (not leading) that I want to keep.

    Example below.

    Here is what I have now:

    ColD
    This is the text
    Blah Blah Blah
    Blah Blah Blah Blah
    This is the text

    Here is what I'd like to end up with:

    ColD
    This is the text
    Blah Blah Blah
    Blah Blah Blah Blah
    This is the text

    Thanks in advance!

    Scott
    I must either be either rather pissed or need to get my eye sight tested but there does not seem to a difference between what you have now and what you want.

  3. #3
    Forum Contributor
    Join Date
    01-19-2006
    Posts
    142
    try using the following;

    Dim i%
    do
    Cells(i, 4).Value = Trim(Cells(i, 4).Value)
    loop until Cells(i, 4).Value = ""

  4. #4
    Don Guillett
    Guest

    Re: VBA help please - remove leading spaces

    try
    =SUBSTITUTE(A14,CHAR(160),"")

    --
    Don Guillett
    SalesAid Software
    [email protected]
    "Scott Wagner" <[email protected]> wrote in message
    news:[email protected]...
    > In column D of my worksheet some of the cell contents have a varying
    > number
    > of spaces. How can I removed any leading spaces from those cells with
    > VBA?
    >
    > There are spaces within the cells (not leading) that I want to keep.
    >
    > Example below.
    >
    > Here is what I have now:
    >
    > ColD
    > This is the text
    > Blah Blah Blah
    > Blah Blah Blah Blah
    > This is the text
    >
    > Here is what I'd like to end up with:
    >
    > ColD
    > This is the text
    > Blah Blah Blah
    > Blah Blah Blah Blah
    > This is the text
    >
    > Thanks in advance!
    >
    > Scott




  5. #5
    Dave Peterson
    Guest

    Re: VBA help please - remove leading spaces

    dim myCell as range
    for each mycell in selection.cells
    mycell.formula = ltrim(mycell.formula)
    next mycell




    Scott Wagner wrote:
    >
    > In column D of my worksheet some of the cell contents have a varying number
    > of spaces. How can I removed any leading spaces from those cells with VBA?
    >
    > There are spaces within the cells (not leading) that I want to keep.
    >
    > Example below.
    >
    > Here is what I have now:
    >
    > ColD
    > This is the text
    > Blah Blah Blah
    > Blah Blah Blah Blah
    > This is the text
    >
    > Here is what I'd like to end up with:
    >
    > ColD
    > This is the text
    > Blah Blah Blah
    > Blah Blah Blah Blah
    > This is the text
    >
    > Thanks in advance!
    >
    > Scott


    --

    Dave Peterson

  6. #6
    Scott Wagner
    Guest

    Re: VBA help please - remove leading spaces

    Thanks to all for responding!



    "Dave Peterson" wrote:

    > dim myCell as range
    > for each mycell in selection.cells
    > mycell.formula = ltrim(mycell.formula)
    > next mycell
    >
    >
    >
    >
    > Scott Wagner wrote:
    > >
    > > In column D of my worksheet some of the cell contents have a varying number
    > > of spaces. How can I removed any leading spaces from those cells with VBA?
    > >
    > > There are spaces within the cells (not leading) that I want to keep.
    > >
    > > Example below.
    > >
    > > Here is what I have now:
    > >
    > > ColD
    > > This is the text
    > > Blah Blah Blah
    > > Blah Blah Blah Blah
    > > This is the text
    > >
    > > Here is what I'd like to end up with:
    > >
    > > ColD
    > > This is the text
    > > Blah Blah Blah
    > > Blah Blah Blah Blah
    > > This is the text
    > >
    > > Thanks in advance!
    > >
    > > Scott

    >
    > --
    >
    > Dave Peterson
    >


  7. #7
    Don Guillett
    Guest

    Re: VBA help please - remove leading spaces

    what worked?

    --
    Don Guillett
    SalesAid Software
    [email protected]
    "Scott Wagner" <[email protected]> wrote in message
    news:[email protected]...
    > Thanks to all for responding!
    >
    >
    >
    > "Dave Peterson" wrote:
    >
    >> dim myCell as range
    >> for each mycell in selection.cells
    >> mycell.formula = ltrim(mycell.formula)
    >> next mycell
    >>
    >>
    >>
    >>
    >> Scott Wagner wrote:
    >> >
    >> > In column D of my worksheet some of the cell contents have a varying
    >> > number
    >> > of spaces. How can I removed any leading spaces from those cells with
    >> > VBA?
    >> >
    >> > There are spaces within the cells (not leading) that I want to keep.
    >> >
    >> > Example below.
    >> >
    >> > Here is what I have now:
    >> >
    >> > ColD
    >> > This is the text
    >> > Blah Blah Blah
    >> > Blah Blah Blah Blah
    >> > This is the text
    >> >
    >> > Here is what I'd like to end up with:
    >> >
    >> > ColD
    >> > This is the text
    >> > Blah Blah Blah
    >> > Blah Blah Blah Blah
    >> > This is the text
    >> >
    >> > Thanks in advance!
    >> >
    >> > Scott

    >>
    >> --
    >>
    >> Dave Peterson
    >>




+ 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