View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Pawan Pawan is offline
external usenet poster
 
Posts: 87
Default macro to remove space

That worked William
Thank You

"William Benson" wrote:

You could use a macro to invoke the TRIM function on each cell, however this
also will turn phrases like

"Bill Benson "
into
"Bill Benson"

which may not be what you want to do.

If you want only to remove any right-most spaces, use the function RTRIM.

Sub RemoveSpaces()
Dim Rng As Range, Cell As Range
Set Rng = ActiveSheet.UsedRange
For Each Cell In Rng
If Not IsEmpty(Cell) _
And Len(Cell) = 1 _
And Right(Cell, 1) = Chr(32) _
And Not Cell.HasFormula Then _
Cell = RTrim(Cell)
Next
End Sub





"Pawan" wrote in message
...
Hi All

I have an excel sheet with lot of text in cells. e.g. "This is a school
". There is space after word school. Same situation is for many cells. I
want
to remove this space. Is it possible to write a macro for this?

Thank you in advance.

-Pawan