Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default trimming whitespace

Can I trim all whitespace from a string, turning "cat<any number of spaces,
plus if possible any number of tabsdog" into "catdog"?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default trimming whitespace

sStr = Application.Substitute(Application.Substitute(str1 ," ",""),chr(9),"")

demo'd from the immediate window:

sStr1 = "cat " & vbTab & " " & vbTab & vbTab & " " & vbtab & "dog"
? sStr1
cat dog
? Application.Substitute(Application.Substitute(sStr 1," ",""),chr(9),"")
catdog

--
Regards,
Tom Ogilvy




"Jamie Martin" wrote in message
...
Can I trim all whitespace from a string, turning "cat<any number of

spaces,
plus if possible any number of tabsdog" into "catdog"?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default trimming whitespace

Jamie,

Try this formula-

=SUBSTITUTE(SUBSTITUTE(D2,CHAR(9),"")," ","")

regards,

JohnI

"Jamie Martin" wrote in message
...
Can I trim all whitespace from a string, turning "cat<any number of

spaces,
plus if possible any number of tabsdog" into "catdog"?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default trimming whitespace


Jamie,

this is my trim function. Just add space in the list (you should not be able
to have tabs within a string, just spaces). It should do the job. It also
takes in a parameter if you want to cut the string after a certain number of
characters (charts having more than 32 characters in the name of it start to
behave oddly, that's why I have it).

HTH,
Jouni
Finland

Function TrimString(strString As String, intLength As Integer) As String
' removes illegal characters for worksheets and charts.
' sets length as passed.
Dim intChar As Integer
For intChar = 1 To Len(strString)
If Mid(strString, intChar, 1) < "/" And Mid(strString, intChar, 1)
< "\" And _
Mid(strString, intChar, 1) < "*" And Mid(strString, intChar, 1)
< "?" And _
Mid(strString, intChar, 1) < ":" And Mid(strString, intChar, 1)
< " " And _
Mid(strString, intChar, 1) < "," And Mid(strString, intChar, 1)
< "." And _
Mid(strString, intChar, 1) < "(" And Mid(strString, intChar, 1)
< ")" And _
Mid(strString, intChar, 1) < "[" And Mid(strString, intChar, 1)
< "]" And _
Mid(strString, intChar, 1) < "-" And Mid(strString, intChar, 1)
< "&" And _
Mid(strString, intChar, 1) < "'" And Mid(strString, intChar, 1)
< ";" And _
Mid(strString, intChar, 1) < "_" And Mid(strString, intChar, 1)
< "anything_crap" Then
TrimString = TrimString & Mid(strString, intChar, 1)
End If
Next
TrimString = Left(TrimString, intLength)
End Function



"Jamie Martin" wrote in message
...
Can I trim all whitespace from a string, turning "cat<any number of

spaces,
plus if possible any number of tabsdog" into "catdog"?




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default trimming whitespace

Just another similar option:

Sub Demo()

Dim s As String
s = "cat " & vbTab & " " & vbLf & vbTab & " " & vbCrLf & "dog"
s = Replace(WorksheetFunction.Clean(s), Space(1), vbNullString)

'// or
s = "cat " & vbTab & " " & vbLf & vbTab & " " & vbCrLf & "dog"
With WorksheetFunction
s = .Substitute(.Clean(s), Space(1), vbNullString)
End With

End Sub

--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"Jamie Martin" wrote in message
...
Can I trim all whitespace from a string, turning "cat<any number of

spaces,
plus if possible any number of tabsdog" into "catdog"?




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 not trimming Kim Excel Worksheet Functions 7 August 10th 07 12:48 AM
TRIM not trimming Kim Excel Worksheet Functions 0 August 8th 07 11:22 PM
Chart whitespace [email protected] Charts and Charting in Excel 1 July 10th 07 03:33 PM
IP Trimming Josh Excel Discussion (Misc queries) 1 June 16th 06 04:34 PM
what does whitespace not allowed in this location mean and how do. garfland Excel Discussion (Misc queries) 0 April 19th 05 03:47 PM


All times are GMT +1. The time now is 02:27 PM.

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"