Strip leading spaces from cell

P

Pete

I need a formula to remove/delete leading spaces from a cell.

column b contains data imported from anothe application. unfortuantly some
of these cells have padded leading blanks added.

I need to remove these. but 3000+ cells individually will take hours.

any help?
 
D

David McRitchie

If they are from another application they may not be spaces,
they could be CHAR(160) which is a Required blank (RBL),
or in HTML is know as a nonbreaking space ( )

If you really only want to trim the leading space you would use
LTRIM in VBA but you probably want to trim both sides as previously
suggested.

I would recommend doing this with a macro so that you can change
things in place rather than the little dance routine of creating a helper
column, converting that column to constants and then removing the
original. If you enjoy doing the extra steps and it is CHAR(160)
you could look at my strings.htm page and use something like
=TRIM( SUBSTITUTE(A21, CHAR(160)," ") )
there is no LTRIM function in worksheet functions but there is in VBA

But for a macro to trim both sides and possible excessive spaces in between see
http://www.mvps.org/dmcritchie/excel/join.htm#trimall
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top