Delete spaces

  • Thread starter Thread starter rexmann
  • Start date Start date
R

rexmann

Hi All

Is there a formula that deletes all the spaces at the end of a cell of text
but not the spaces in the middle of the cell?

Cheers Rexmann

PS Excel 2003
 
Hi All

Is there a formula that deletes all the spaces at the end of a cell of text
but not the spaces in the middle of the cell?

Cheers Rexmann

PS Excel 2003

The TRIM worksheet function will delete spaces at the beginning and end, and
also leave only a single space between words within the text string.

To delete ONLY the spaces at the end, you can try this formula:

=LEFT(A1,LEN(A1)-SUMPRODUCT(--(TRIM(MID(A1,1+
LEN(A1)-ROW(INDIRECT("1:"&LEN(A1))),255))="")))

--ron
 
The TRIM worksheet function will delete spaces at the beginning and end, and
also leave only a single space between words within the text string.

To delete ONLY the spaces at the end, you can try this formula:

=LEFT(A1,LEN(A1)-SUMPRODUCT(--(TRIM(MID(A1,1+
LEN(A1)-ROW(INDIRECT("1:"&LEN(A1))),255))="")))

--ron

Or (slightly shorter):

=LEFT(A1,LEN(A1)+SUMPRODUCT(-(TRIM(MID(A1,1+
LEN(A1)-ROW(INDIRECT("1:"&LEN(A1))),255))="")))

--ron
 
Maybe one of these:

For all text lengths:
=LEFT(A1,COUNT(INDEX(1/(TRIM(RIGHT(A1,ROW(INDEX($A:$A,1):
INDEX($A:$A,LEN(A1)))))<>""),0)))

or...if the text length will be 255 chars or less:
=LEFT(A1,COUNT(INDEX(1/(TRIM(RIGHT(A1,COLUMN($1:$65536)))<>""),0)))

Does that help?
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)
 

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

Similar Threads

Split column on first space 2
Delete space at beginning 4
Capitals 3
PDF multiple sheets 2
Pivot value not formula 1
Vlookup - value not formula 1
Vlookup - actual value not the formula 3
Split cell 3

Back
Top