Deleting unwanted characters in a txt

Shogman

New Member
Joined
Feb 13, 2012
Messages
11
I use this code to write to a txt file:

Dim rCell As Range
Dim rRow As Range
Dim sOutput As String
Dim sFname As String, lFnum As Long

'Open a text file to write
sFname = "\\SERVER\Company\FÖRETAGEN\RTFL Care AB\Tidrapporter\" + Range("e3").Value + ".txt"
lFnum = FreeFile

Open sFname For Output As lFnum
'Loop through the rows'
For Each rRow In ActiveSheet.UsedRange.Rows
'Loop through the cells in the rows'
For Each rCell In rRow.Cells
sOutput = sOutput & rCell.Value & ";"
Next rCell
'remove the last comma'
sOutput = Left(sOutput, Len(sOutput) - 1)

'write to the file and reinitialize the variables'
Print #lFnum, sOutput
sOutput = ""
Next rRow
Close lFnum

It works excellent, but file looks like this:

[TidTr]AnstId;Datum;ProdId;Beskr;KundId;Tid;Pt;Pris
[TidTr];;;;;;;
1;2012-01-01;11;OB Vardag;XX100;4;XX100;267

and I don't want the semicolons in line 2. The file is used for loading into an Access data base [TidTr] and Access doesn't understand in which database to load if the semicolons are there.

How do I get rid of them?
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Can't you just write a check to see if rCell has a value?

Code:
If rCell <> "" then sOutput = sOutput & rCell.Value & ";"
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,217
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top