Thread: Spaces
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Wild Bill[_2_] Wild Bill[_2_] is offline
external usenet poster
 
Posts: 90
Default Spaces

On 27 Aug 2003 06:51:26 -0700, (Arnie) wrote:
The VBA Trim function works differently than the Excel Trim function.
In Excel all extra spaces are removed, including those between words.


Really? Try the following in a cell
=TRIM("Arnie at ajcomputers")
or in VBA,
rng = WorksheetFunction.Trim(rng.Text)

Excel's trim does compress multiple spaces which might be useful, but at
any rate OP stated "beginning" twice so I suggested ltrim.

On 27 Aug 2003 06:51:26 -0700,
(Arnie) wrote:
Richard's solution is perfect.


That code won't execute for me. What version of Excel do you use?

On Wed, 27 Aug 2003 03:57:51 -0700, "Richard Daniels"
wrote:
Sub removeSpaces()
Dim rng As Range
With ActiveSheet
For Each rng In .UsedRange
If Left(rng.Text, 1) = " " Then
rng = Replace(rng.Text, " ", "")
End If
Next
End With
End Sub