copy and save as csv

P

pcorcele

I have data in col a to e:
I would like a macro that would copy all the data(all the way to the bottom) and then save that data as a CSV file.
I would appreciate any help I can get with this
Thanks
Ian M
 
C

Claus Busch

Hi Ian,

Am Sun, 28 Apr 2013 06:43:21 -0700 (PDT) schrieb pcorcele:
I have data in col a to e:
I would like a macro that would copy all the data(all the way to the bottom) and then save that data as a CSV file.

try:
Sub SaveAsCSV()
Dim WbkName As String
Dim myPath As String

WbkName = "Test"
myPath = "C:\Users\Claus Busch\Desktop\"
Sheets("Tabelle1").Copy
ActiveWorkbook.SaveAs Filename:=myPath & WbkName & ".csv", _
FileFormat:=xlCSV, CreateBackup:=False
ActiveWorkbook.Close
End Sub


Regards
Claus Busch
 
A

Auric__

pcorcele said:
I have data in col a to e:
I would like a macro that would copy all the data(all the way to the
bottom) and then save that data as a CSV file.
I would appreciate any help I can get with this

If you only have data in the range A:E, I'd say use Claus' solution. But if
you have data outside those columns that you don't want exported, you might
try this instead:

Sub copyA_EtoCSV()
fileout = FreeFile
Open "data.csv" For Output As fileout
For r = 1 To Range("A:E").SpecialCells(xlCellTypeLastCell).Row
Write #fileout, Cells(r, 1).Value, Cells(r, 2).Value, _
Cells(r, 3).Value, Cells(r, 4).Value, Cells(r, 5).Value
Next
Close fileout
End Sub

(This will also work if there's only data in A:E like Claus' code, but this
makes sure that anything beyond column E isn't exported, regardless.)

In both Claus' code and mine above, the path for the CSV needs to be set
appropriately. (Claus shows how to do it based on where the workbook is; I
use a fixed location.)
 
P

pcorcele

I have data in col a to e:

I would like a macro that would copy all the data(all the way to the bottom) and then save that data as a CSV file.

I would appreciate any help I can get with this

Thanks

Ian M

Thanks for all the help.I did try your suggestions......But I found out that I did not give you all the info required. Using your suggestions, copied the ENTURE file. My file consists of THREE sheets. I just want to copy the first sheet which is called MYMOVIES. I would appreciate any help with this
and thanks
Ian M
 
C

Claus Busch

Hi Ian,

Am Mon, 29 Apr 2013 06:52:43 -0700 (PDT) schrieb pcorcele:
Thanks for all the help.I did try your suggestions......But I found out that I did not give you all the info required. Using your suggestions, copied the ENTURE file. My file consists of THREE sheets. I just want to copy the first sheet which is called MYMOVIES. I would appreciate any help with this
and thanks

change the line with copy to:
Sheets("MYMOVIES").Copy


Regards
Claus Busch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top