#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Trim in VBA

Excel 2002, WinXP
The worksheet Trim function removes all trailing and leading spaces and the
more-than-one spaces between words. The VBA Trim command does not address
the spaces between words.
Is there a variation of the Trim command that does address the excess
spaces between words or do I have to use the worksheet function in VBA to do
that? Thanks for your help. Otto


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 292
Default Trim in VBA

Hi Otto

I think the worksheet function is the best way to do it:

Sub test()
Dim s As String
s = " Hi There Otto "
s = Application.Trim(s)
MsgBox "*" & s & "*"
End Sub

HTH. best wishes Harald

"Otto Moehrbach" skrev i melding
...
Excel 2002, WinXP
The worksheet Trim function removes all trailing and leading spaces and

the
more-than-one spaces between words. The VBA Trim command does not address
the spaces between words.
Is there a variation of the Trim command that does address the excess
spaces between words or do I have to use the worksheet function in VBA to

do
that? Thanks for your help. Otto




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Trim in VBA

Only the worksheetfunction TRIM does that.

--
Regards,
Tom Ogilvy

"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
The worksheet Trim function removes all trailing and leading spaces and

the
more-than-one spaces between words. The VBA Trim command does not address
the spaces between words.
Is there a variation of the Trim command that does address the excess
spaces between words or do I have to use the worksheet function in VBA to

do
that? Thanks for your help. Otto




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Trim in VBA

Otto

Worksheet Function only.

Sub TRIM_EXTRA_SPACES()
Dim cell As Range
For Each cell In Selection
If (Not IsEmpty(cell)) And _
Not IsNumeric(cell.Value) And _
InStr(cell.Formula, "=") = 0 _
Then cell.Value = Application.Trim(cell.Value)
Next
End Sub

Gord Dibben Excel MVP

On Tue, 18 May 2004 07:14:16 -0400, "Otto Moehrbach"
wrote:

Excel 2002, WinXP
The worksheet Trim function removes all trailing and leading spaces and the
more-than-one spaces between words. The VBA Trim command does not address
the spaces between words.
Is there a variation of the Trim command that does address the excess
spaces between words or do I have to use the worksheet function in VBA to do
that? Thanks for your help. Otto


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Trim in VBA

Harald, Tom, & Gord
Thanks for your help. Otto
"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
The worksheet Trim function removes all trailing and leading spaces and

the
more-than-one spaces between words. The VBA Trim command does not address
the spaces between words.
Is there a variation of the Trim command that does address the excess
spaces between words or do I have to use the worksheet function in VBA to

do
that? Thanks for your help. Otto




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
=TRIM Shayra Excel Discussion (Misc queries) 5 October 16th 08 07:16 PM
trim Chey Excel Discussion (Misc queries) 4 July 16th 07 07:58 PM
TRIM s99drf New Users to Excel 3 April 27th 07 08:46 PM
Trim help please Dave New Users to Excel 8 September 1st 05 07:18 PM
Trim like worksheet Trim Bob Phillips[_5_] Excel Programming 0 August 20th 03 07:10 PM


All times are GMT +1. The time now is 09:36 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"