Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default How to remove spaces from a word in a cell

I want to do it automatically for a group of cells.

for example, if the word in a cell is "a b c", after spaces are
removed, the new word in the cell will be "abc"

how to do it by using VBA? thanks!

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 26
Default How to remove spaces from a word in a cell

Anything wrong with the Substitute function for this cause?

=SUBSTITUTE(A1," ","") where A1 is the cell location of the text.

"a b c" becomes "abc".
--
Y


"Jerry" wrote:

I want to do it automatically for a group of cells.

for example, if the word in a cell is "a b c", after spaces are
removed, the new word in the cell will be "abc"

how to do it by using VBA? thanks!


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15,768
Default How to remove spaces from a word in a cell

Try this macro:

Sub RemSpace()

Dim cell As Range
For Each cell In Selection
Selection.Replace What:=" ", Replacement:="", _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False, _
SearchFormat:=False, _
ReplaceFormat:=False

Next cell

End Sub

Select the range of cells in question then run the macro.

You really don't need a macro to do this. You can do the same by following
these steps:

Select the range of cells in question
Goto the menu EditReplace
Find what: enter a space in the box by hitting your space bar
Replace with: nothing, leave this empty
Replace all
Close

Biff

"Jerry" wrote in message
ups.com...
I want to do it automatically for a group of cells.

for example, if the word in a cell is "a b c", after spaces are
removed, the new word in the cell will be "abc"

how to do it by using VBA? thanks!



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 340
Default How to remove spaces from a word in a cell

It's easy to get the VBA code by using Tools Macro Record New Macro
and then using the EditReplace method.

BTW The "for each cell" loop is redundant in the code above.

T. Valko wrote:

Try this macro:

Sub RemSpace()

Dim cell As Range
For Each cell In Selection
Selection.Replace What:=" ", Replacement:="", _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False, _
SearchFormat:=False, _
ReplaceFormat:=False

Next cell

End Sub

Select the range of cells in question then run the macro.

You really don't need a macro to do this. You can do the same by following
these steps:

Select the range of cells in question
Goto the menu EditReplace
Find what: enter a space in the box by hitting your space bar
Replace with: nothing, leave this empty
Replace all
Close

Biff

"Jerry" wrote in message
ups.com...
I want to do it automatically for a group of cells.

for example, if the word in a cell is "a b c", after spaces are
removed, the new word in the cell will be "abc"

how to do it by using VBA? thanks!


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15,768
Default How to remove spaces from a word in a cell

BTW The "for each cell" loop is redundant in the code above.

That's why I almost never post code! Good pointer, though.

Biff

"Lori" wrote in message
oups.com...
It's easy to get the VBA code by using Tools Macro Record New Macro
and then using the EditReplace method.

BTW The "for each cell" loop is redundant in the code above.

T. Valko wrote:

Try this macro:

Sub RemSpace()

Dim cell As Range
For Each cell In Selection
Selection.Replace What:=" ", Replacement:="", _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False, _
SearchFormat:=False, _
ReplaceFormat:=False

Next cell

End Sub

Select the range of cells in question then run the macro.

You really don't need a macro to do this. You can do the same by
following
these steps:

Select the range of cells in question
Goto the menu EditReplace
Find what: enter a space in the box by hitting your space bar
Replace with: nothing, leave this empty
Replace all
Close

Biff

"Jerry" wrote in message
ups.com...
I want to do it automatically for a group of cells.

for example, if the word in a cell is "a b c", after spaces are
removed, the new word in the cell will be "abc"

how to do it by using VBA? thanks!






  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default How to remove spaces from a word in a cell

Another option would be to just edit|Replace the space character with nothing:

In code:

Option Explicit
Sub testme01()
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
End Sub

Select the range to fix first.

"T. Valko" wrote:

Try this macro:

Sub RemSpace()

Dim cell As Range
For Each cell In Selection
Selection.Replace What:=" ", Replacement:="", _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False, _
SearchFormat:=False, _
ReplaceFormat:=False

Next cell

End Sub

Select the range of cells in question then run the macro.

You really don't need a macro to do this. You can do the same by following
these steps:

Select the range of cells in question
Goto the menu EditReplace
Find what: enter a space in the box by hitting your space bar
Replace with: nothing, leave this empty
Replace all
Close

Biff

"Jerry" wrote in message
ups.com...
I want to do it automatically for a group of cells.

for example, if the word in a cell is "a b c", after spaces are
removed, the new word in the cell will be "abc"

how to do it by using VBA? thanks!


--

Dave Peterson
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 trailing spaces from multiple columns in Excel dcaissie Excel Worksheet Functions 8 May 16th 08 08:21 PM
Cell References [email protected] Excel Discussion (Misc queries) 2 November 15th 06 11:37 PM
Putting a word into a cell. the-jackal New Users to Excel 2 September 15th 06 08:03 AM
how to remove spaces in a middle of a cell example '25 566 589. P.M.SANJAY Excel Discussion (Misc queries) 1 January 6th 06 07:23 PM
Copy cell format to cell on another worksht and update automatical kevinm Excel Worksheet Functions 21 May 19th 05 11:07 AM


All times are GMT +1. The time now is 10:54 PM.

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

About Us

"It's about Microsoft Excel"