View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default macro to delete spaces doesn't compile

I didn't see you in the list.
--
HTH...

Jim Thomlinson


"Dave Peterson" wrote:

I am an Excel MVP.

Jim Thomlinson wrote:

Good point... How is it you are not an MVP yet? I'd vote for you.
--
HTH...

Jim Thomlinson

"Dave Peterson" wrote:

Be careful.

You may want the Intersect() still. If your selection is a single cell, then
the intersect() will mean that you're only working on that single cell.

Without it, the whole worksheet may be affected.

But you don't need those () after the .replace:

Intersect(Selection, Selection.SpecialCells(xlConstants, xlTextValues)) _
.Replace ", ", ","

But if you want to remove 2 spaces, don't you want to specify 2 spaces in the
From portion???

Or run it multiple times:

Option Explicit
Sub delSpaces()

Dim iCtr As Long

For iCtr = 1 To 2
Intersect(Selection, Selection.SpecialCells(xlConstants, xlTextValues)) _
.Replace ", ", ","
Next iCtr
End Sub

Janis wrote:

This macro has an error and doesn't compile. I also need it to delete 2
spaces.

Sub delSpaces()

Intersect(Selection, Selection.SpecialCells(xlConstants,
xlTextValues)).replace(", ",",")

End Sub

tia,

--

Dave Peterson


--

Dave Peterson