Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default delete all spaces in range


need to change this to fit all cells in named range "apples".

Sub NoSpaces()
Dim c As Range

For Each c In Selection.Cells
c = Replace(c, " ", "")
Next
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default delete all spaces in range

if i understand correctly, you gave yourself the answer

For Each c In Range("apples")

--


Gary Keramidas
Excel 2003


"J.W. Aldridge" wrote in message
...

need to change this to fit all cells in named range "apples".

Sub NoSpaces()
Dim c As Range

For Each c In Selection.Cells
c = Replace(c, " ", "")
Next
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default delete all spaces in range

is there a quicker way to execute this?

it's taking almost 5-10 minutes as is.

thanx
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default delete all spaces in range

Can you just use Edit|Replace to replace all the space characters (match entire
cell, though) with nothing?

Select the range first.

"J.W. Aldridge" wrote:

need to change this to fit all cells in named range "apples".

Sub NoSpaces()
Dim c As Range

For Each c In Selection.Cells
c = Replace(c, " ", "")
Next
End Sub


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default delete all spaces in range

Unsure if its faster but consider:

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


Obviously you could speed it even further by changing Cells. to a
specific range.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default delete all spaces in range

I wouldn't use xlpart for this.

Youmayfindthatyouendupwithwordsstucktogetherinally ournonemptycells.

But if there's a chance that the original poster has multiple spaces in the cell
and has to get rid of all of those then maybe something like this:

Option Explicit
Sub testme()
Dim myRng As Range
Dim iCtr As Long
Dim MaxSpacesToFix As Long

MaxSpacesToFix = 10

With Worksheets("Sheet1")
Set myRng = .Range("A1").EntireColumn
End With

For iCtr = 1 To MaxSpacesToFix
myRng.Replace what:=Space(iCtr), _
replacement:="", _
lookat:=xlWhole, _
searchorder:=xlNext, _
MatchCase:=False
Next iCtr

End Sub

Adjust the maxspacestofix to what you know(?) it can't exceed.

Jef Gorbach wrote:

Unsure if its faster but consider:

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

Obviously you could speed it even further by changing Cells. to a
specific range.


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 72
Default delete all spaces in range

try this then:

Sub NoSpaces()
Dim c As Range
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For Each c In Range("apples")

c = Replace(c, " ", "")
Next

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub


--


Gary Keramidas
Excel 2003


"J.W. Aldridge" wrote in message
...
is there a quicker way to execute this?

it's taking almost 5-10 minutes as is.

thanx


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
Delete spaces rexmann Excel Discussion (Misc queries) 4 March 7th 08 02:38 PM
Delete Variable spaces at beginning of a range gmunro Excel Programming 4 August 21st 07 02:26 PM
delete spaces abugoli Excel Programming 4 June 27th 07 09:06 AM
delete spaces CHARI Excel Worksheet Functions 2 September 9th 05 10:38 AM
Help copying a range with spaces to a range without spaces Andy Excel Programming 1 September 23rd 03 04:26 PM


All times are GMT +1. The time now is 07:48 AM.

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"