Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Using Trim in a Userform

Here's a function from my standard library that I use to trim and
single space a string. It is pure VBA, with no reliance on Excel, so
can be used in any VBA application.

Function SingleSpace(S As String) As String
Dim T As String
Dim N As Long
T = Trim(S)
N = InStr(1, T, Space(2), vbBinaryCompare)
Do Until N = 0
T = Replace(T, Space(2), Space(1))
N = InStr(1, T, Space(2), vbBinaryCompare)
Loop
SingleSpace = T
End Function

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com


On Mon, 24 May 2010 00:14:12 -0400, "Rick Rothstein"
wrote:

When I run your code, I get two spaces left between words, not one.

I'm guessing you didn't see my first posting in this thread, did you? Here
is what I posted modified to fit your function header...

Function StripExtraSpaces(ByVal InputString As String) As String
StripExtraSpaces = WorksheetFunction.Trim(InputString)
End Function

This code, which is much shorter than yours, outputs what I think you
intended your function to output.

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 Help ! Nikki Excel Discussion (Misc queries) 8 April 22nd 09 06:20 PM
TRIM Nikki Excel Discussion (Misc queries) 3 April 22nd 09 05:56 PM
VLOOKUP Trim vs. No Trim Kigol Excel Programming 2 October 3rd 07 05:14 PM
VBA Trim and Application.worksheetfunction.Trim Hari Prasadh Excel Programming 3 January 19th 05 02:22 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:34 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"