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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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,223,893
Messages
6,175,244
Members
452,622
Latest member
Laura_PinksBTHFT

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