Solved

VBA remove commas

Posted on 2012-03-14
5
475 Views
Last Modified: 2012-03-30
i am trying to find some code that will remove commas from a csv file.
i am trying to import a csv file using ssis but the commas screw my fields up.
0
Comment
Question by:aneilg
  • 2
  • 2
5 Comments
 
LVL 46

Accepted Solution

by:
Martin Liss earned 155 total points
ID: 37720628
Dim strBuffer As String
' Define an Integer to hold the file number
Dim FF As Integer

' Find a file number that's not in use
FF = FreeFile

Open "c:\temp\Test.txt" For Input As #FF

' The format of 'Input' is Input(how-many-bytes, file-number) and
' LOF is Length Of File so how-many-bytes is set at length of the file
strBuffer = Input(LOF(FF), FF)
strBuffer = Replace(strBuffer, "," , "|") ' replace the commas with |. You could also use " " or ""
Close #FF
Kill "c:\temp\Test.txt"
Open "c:\temp\Test.txt" For Output As #FF
Print #FF, strBuffer
Close #FF
0
 

Author Comment

by:aneilg
ID: 37720685
thank i'll give it a go.
0
 
LVL 92

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 155 total points
ID: 37722400
Normally the comma would be your delimiter in a CSV file.

Is the problem that some of your actual values themselves have commas?
0
 

Author Closing Comment

by:aneilg
ID: 37786889
partly answered
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 37787290
Instead of a "C" grade you could have asked for more help with whatever problem(s) remained.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now