Export to csv.

Nomas

Board Regular
Joined
Jun 14, 2011
Messages
91
Hi there,

Using Excel 2007, I am looking to select a specific sheet out of a multiple sheet workbook, delete the 1st 2 header rows, and save only that sheet as a csv. When I try to do it through recording it, it saves that sheet but I cant get back to the macro because its not saved due to it being in text format now it only kept 1 sheet. I appreciate any guidance.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I have a workbook that I use to collect my macros. Then I can use it on any file. I don't like the Personal workbook, so instead a just have a sheet that I open everyday that has the hundreds of macros. Just a suggested route that would help you in your situation.
 
Upvote 0
Try this:
Rich (BB code):

Sub SaveCsvSheet()
  
  ' CSV source sheet name, change to suit
  Const CsvSheet = "Sheet2"
  
  Dim CsvFile As String
  
  ' Define CSV full name
  With ActiveWorkbook
    CsvFile = Left(.FullName, Len(.FullName) - 5) & "_" & CsvSheet & ".CSV"
  End With
  
  On Error GoTo exit_
  
  ' Copy CSV source sheet into new workbook
  Sheets(CsvSheet).Copy
  ' Suppress dialog
  Application.DisplayAlerts = False
  ' Delete 2 top rows
  Rows("1:2").Delete
  ' Save as CSV and close
  With ActiveWorkbook
    .SaveAs Filename:=CsvFile, FileFormat:=xlCSV, CreateBackup:=False, Local:=True
    .Close False
  End With
  
exit_:
  Application.DisplayAlerts = True
  If Err Then MsgBox Err.Description
  
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,749
Members
452,940
Latest member
rootytrip

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