Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default macro to remove space

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default macro to remove space

Simply start recording a macro, select the entire sheet, go to find /
replace, and replace "school " with "school" (without the double-quotes
ofcourse). Stop recording the macro. Check the macro code which would be
something like this.


Sub Macro1()
Cells.Select
Selection.Replace What:="school ", Replacement:="school", LookAt:=xlPart
_
, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End Sub


You could also try running the above code.

Mangesh





"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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default macro to remove space

is there text after the word with the space after it, or is the space the
last character?

--


Gary


"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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 230
Default macro to remove space

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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default macro to remove space

try David Mcritchie's <trimallmacro.


"William Benson" wrote in message
...
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







  #6   Report Post  
Posted to microsoft.public.excel.programming
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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
remove space capreecorn Excel Worksheet Functions 4 March 17th 09 03:45 PM
Macro to remove space at front and end of a cell yhoy Excel Discussion (Misc queries) 2 February 22nd 08 09:53 PM
How to remove a space Kevin Excel Discussion (Misc queries) 5 July 20th 07 01:24 PM
Function to remove a space from text in cell WITHOUT macro?? [email protected] Excel Worksheet Functions 5 May 28th 05 02:28 AM
Macro to remove leading space Andrew[_19_] Excel Programming 4 August 29th 03 04:14 PM


All times are GMT +1. The time now is 11:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"