Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Removing every second instance of comma sign

I need to import .csv files into excel. Problem is that the program
that exports the .csv files comma sepatates the values and the values
themselves contain commas. For example:

3,14,-1,28,0,74

Should be interpreted as:

3,14 -1,28 0,74

The only thing I have going for me is that all the values contain
commas. This means I should be able to replace every second comma with
another delimiter and thus be able to read the file correctly.
Something like this:

3,14;-1,28;0,74

Iīve been thinking about how to go about this but havenīt been able to
come up with anything that works. Does anyone have any suggestions on
how to replace every second comma in a string?

Regards / Thomas L
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Removing every second instance of comma sign

Thomas,

This may do what you want...
'--------------------------------------------
Sub SecondCommasAreNotWorthy()
'Jim Cone - San Francisco, USA - Feb 11, 2005
'Replaces every second comma in every cell in
'the selection with a space.

Dim lngN As Long
Dim lngCount As Long
Dim strValue As String
Dim rngCell As Excel.Range

' The cells to change must be selected.
For Each rngCell In Selection
strValue = rngCell.Value
'Go thru each character in the cell
For lngN = 1 To Len(strValue)
'Identify commas
If Asc(Mid$(strValue, lngN, 1)) = 44 Then
lngCount = lngCount + 1
'Is the count of commas divisible by 2.
If lngCount Mod 2 = 0 Then
'Replace comma with space
Mid$(strValue, lngN, 1) = " "
End If
End If
Next 'lngN
'Replace text in the cell with new text.
rngCell.Value = strValue
lngCount = 0
'Now do it again
Next 'rngCell
Set rngCell = Nothing
End Sub
'-----------------------------------------------

Regards,
Jim Cone
San Francisco, USA


"Triple7" wrote in message
om...
I need to import .csv files into excel. Problem is that the program
that exports the .csv files comma sepatates the values and the values
themselves contain commas. For example:
3,14,-1,28,0,74
Should be interpreted as:
3,14 -1,28 0,74
The only thing I have going for me is that all the values contain
commas. This means I should be able to replace every second comma with
another delimiter and thus be able to read the file correctly.
Something like this:
3,14;-1,28;0,74
Iīve been thinking about how to go about this but havenīt been able to
come up with anything that works. Does anyone have any suggestions on
how to replace every second comma in a string?
Regards / Thomas L


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Removing every second instance of comma sign

Thanks Jim, that worked great!
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 the "-" sign in a calucation gma Excel Worksheet Functions 8 February 3rd 09 05:23 AM
Removing beginning minus sign from telephone numbers Henrik Johnson Excel Discussion (Misc queries) 6 January 11th 07 03:28 PM
Removing % sign, but keeping the formatting Annabelle Excel Discussion (Misc queries) 2 July 28th 06 07:20 AM
removing comma lucas Excel Worksheet Functions 4 March 9th 06 01:51 PM
Removing a space after a comma DebbieK9 New Users to Excel 3 April 1st 05 10:08 PM


All times are GMT +1. The time now is 11:58 AM.

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"