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

I have this string:

,,,,,206,,,,210,,,,,,217,,,,,222,,,,,,,229,,,233,, ,,,

I would like to output this string:

206,210,217,222,229,233,

How can this be done in VBA?

Reviewing the group, it seems like this snip of code could get me
close, but I am unclear on how to adapt it to my purpose.

-----
Function stripped$(s$)
Const ok = "[#A-z]" '<remove the space here
Dim i%, t$, r$
For i = 1 To Len(s)
t = Mid(s, i, 1)
r = r & iif(t Like ok,t," ")
Next
'optional remove double spaces
'it has to be the worksheetfunction
'vba trim just trims on the outside
r=application.worksheetfunction.trim(r)

stripped = r
End Function

off the cuff.. hope it works :)

keepITcool
-------------

Thanks,
Ray
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Removing commas

Hi Ray,

For the special case of commas only, something like this would be much
faster:

Function szReplaceCommas() As String
Dim szToProcess As String
szToProcess = ",,,,,206,,,,210,,,,,,217,,,,,222,,,,,,,229,,,233, ,,,,"
''' Replace all commas with spaces
szToProcess = Replace(szToProcess, ",", " ")
''' Trim out extra spaces
szToProcess = Application.WorksheetFunction.Trim(szToProcess)
''' Replace spaces with commas and add back trailing comma
szToProcess = Replace(szToProcess, " ", ",") & ","
szReplaceCommas = szToProcess
End Function

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"rcmiv" wrote in message
om...
I have this string:

,,,,,206,,,,210,,,,,,217,,,,,222,,,,,,,229,,,233,, ,,,

I would like to output this string:

206,210,217,222,229,233,

How can this be done in VBA?

Reviewing the group, it seems like this snip of code could get me
close, but I am unclear on how to adapt it to my purpose.

-----
Function stripped$(s$)
Const ok = "[#A-z]" '<remove the space here
Dim i%, t$, r$
For i = 1 To Len(s)
t = Mid(s, i, 1)
r = r & iif(t Like ok,t," ")
Next
'optional remove double spaces
'it has to be the worksheetfunction
'vba trim just trims on the outside
r=application.worksheetfunction.trim(r)

stripped = r
End Function

off the cuff.. hope it works :)

keepITcool
-------------

Thanks,
Ray



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

sStr = ",,,,,206,,,,210,,,,,,217,,,,,222,,,,,,,229,,,233, ,,,,"
sStr = Application.Substitute(sStr,","," ")
sStr = application.Trim(sStr)
sStr = Application.Substitute(sStr," ",",")
? sStr
206,210,217,222,229,233

--
Regards,
Tom Ogilvy




"rcmiv" wrote in message
om...
I have this string:

,,,,,206,,,,210,,,,,,217,,,,,222,,,,,,,229,,,233,, ,,,

I would like to output this string:

206,210,217,222,229,233,

How can this be done in VBA?

Reviewing the group, it seems like this snip of code could get me
close, but I am unclear on how to adapt it to my purpose.

-----
Function stripped$(s$)
Const ok = "[#A-z]" '<remove the space here
Dim i%, t$, r$
For i = 1 To Len(s)
t = Mid(s, i, 1)
r = r & iif(t Like ok,t," ")
Next
'optional remove double spaces
'it has to be the worksheetfunction
'vba trim just trims on the outside
r=application.worksheetfunction.trim(r)

stripped = r
End Function

off the cuff.. hope it works :)

keepITcool
-------------

Thanks,
Ray



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Removing commas

Thanks.


"Rob Bovey" wrote in message ...
Hi Ray,

For the special case of commas only, something like this would be much
faster:

Function szReplaceCommas() As String
Dim szToProcess As String
szToProcess = ",,,,,206,,,,210,,,,,,217,,,,,222,,,,,,,229,,,233, ,,,,"
''' Replace all commas with spaces
szToProcess = Replace(szToProcess, ",", " ")
''' Trim out extra spaces
szToProcess = Application.WorksheetFunction.Trim(szToProcess)
''' Replace spaces with commas and add back trailing comma
szToProcess = Replace(szToProcess, " ", ",") & ","
szReplaceCommas = szToProcess
End Function

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"rcmiv" wrote in message
om...
I have this string:

,,,,,206,,,,210,,,,,,217,,,,,222,,,,,,,229,,,233,, ,,,

I would like to output this string:

206,210,217,222,229,233,

How can this be done in VBA?

Reviewing the group, it seems like this snip of code could get me
close, but I am unclear on how to adapt it to my purpose.

-----
Function stripped$(s$)
Const ok = "[#A-z]" '<remove the space here
Dim i%, t$, r$
For i = 1 To Len(s)
t = Mid(s, i, 1)
r = r & iif(t Like ok,t," ")
Next
'optional remove double spaces
'it has to be the worksheetfunction
'vba trim just trims on the outside
r=application.worksheetfunction.trim(r)

stripped = r
End Function

off the cuff.. hope it works :)

keepITcool
-------------

Thanks,
Ray

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Removing commas

Thanks.


"Tom Ogilvy" wrote in message ...
sStr = ",,,,,206,,,,210,,,,,,217,,,,,222,,,,,,,229,,,233, ,,,,"
sStr = Application.Substitute(sStr,","," ")
sStr = application.Trim(sStr)
sStr = Application.Substitute(sStr," ",",")
? sStr
206,210,217,222,229,233

--
Regards,
Tom Ogilvy




"rcmiv" wrote in message
om...
I have this string:

,,,,,206,,,,210,,,,,,217,,,,,222,,,,,,,229,,,233,, ,,,

I would like to output this string:

206,210,217,222,229,233,

How can this be done in VBA?

Reviewing the group, it seems like this snip of code could get me
close, but I am unclear on how to adapt it to my purpose.

-----
Function stripped$(s$)
Const ok = "[#A-z]" '<remove the space here
Dim i%, t$, r$
For i = 1 To Len(s)
t = Mid(s, i, 1)
r = r & iif(t Like ok,t," ")
Next
'optional remove double spaces
'it has to be the worksheetfunction
'vba trim just trims on the outside
r=application.worksheetfunction.trim(r)

stripped = r
End Function

off the cuff.. hope it works :)

keepITcool
-------------

Thanks,
Ray

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
removing commas from numbers etc. Excel ??[_2_] Excel Worksheet Functions 2 August 10th 07 09:26 AM
Removing patterns without removing gridlines pennyb9 Excel Discussion (Misc queries) 1 July 11th 07 02:43 AM
So many commas Alan[_5_] Excel Worksheet Functions 2 May 24th 07 07:44 PM
tab delimited and commas sedonovan Excel Discussion (Misc queries) 0 July 31st 06 02:31 PM
Removing commas Ernie Sersen Excel Worksheet Functions 1 December 13th 04 05:15 PM


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