Saving .csv files from excel without final Carriage Return.

Purdydog

New Member
Joined
Sep 6, 2017
Messages
2
Apologies if this has been answered before, I can find similar topics but not an exact solution

I need to create a .csv file from data in an excel worksheet for use in another application.

When the csv file is created there is always a final carriage return / blank line which requires manually deleting before the file can be used.

Is there a way to stop this happening?

I'm using excel 2016 bundled with office 365


Thanks.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
here is what i use:

Rich (BB code):
Sub outputtotextfile()
wline = ""

For r = 1 To Range("A65536").End(xlUp).Row
    lcol = Cells(r, 256).End(xlToLeft).Column
    wline = wline & Join(Application.Transpose(Application.Transpose(Range("A" & r).Resize(, lcol))), ",") & vbNewLine
Next r
    
 
   Open "C:\results\test2.txt" For Output As #1  'Replaces existing file
   Print #1 , wline
   Close #1 

End Sub

hth,
Ross
 
Upvote 0
Hi Ross,

Thanks for the reply, (I think I found your code on via an earlier google search)

Showing my VBA naivety, I don't fully understand it but have given it a go.

Here the code :-I'm getting a type mismatch error on the line highlighted in bold.
Sub outputtotextfile()
wline = ""
For r = 1 To Range("A65536").End(xlUp).Row
lcol = Cells(r, 256).End(xlToLeft).Column
wline = wline & Join(Application.Transpose(Application.Transpose(Range("A" & r).Resize(, lcol))), ",") & vbNewLine
Next r


Open "E:\testa.txt" For Output As #1 'Replaces existing file
Print #1 , wline
Close #1
End Sub


I'm guessing I'm missing something??



Thanks,

Barry.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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