How to extract a list of selected cells into a CSV file

2

I have a huge Excel sheet and I would like to get a small list of cell (around 200-300 cells from the same column, row) into a CSV string.

Is there an Excel command to do that?. Saving the file into a CSV is not much of a help as the file is quite huge.

Moslem Ben Dhaou

Posted 2013-10-25T07:36:25.880

Reputation: 135

1Would it be an option to just copy the selected area and paste it into another worksheet? This would be quite simple with VBa – Dave – 2013-10-25T07:48:01.847

Answers

1

You can use a VBA-macro. Change the range, to whatever you want. I choose A1:B3. Also you should change the filepath to a path, which you like.

Sub CopyToCSV()
Sheets(1).Range("A1:B3").Copy
    Workbooks.Add
    ActiveSheet.Paste
    ActiveWorkbook.SaveAs Filename:= _
    "C:\Temp\yourCSV.csv" _
    , FileFormat:=xlCSV, CreateBackup:=False, Local:=True
    Application.DisplayAlerts = False
    ActiveWorkbook.Close
    Application.DisplayAlerts = True

End Sub

How to add a button to the excel-sheet to execute the macro

  1. Add a button (Form control)

    1. If the Developer tab is not available, display it.
      1. Click the Microsoft Office Button Button image, and then click Excel Options.
      2. In the Popular category, under Top options for working with Excel, select the Show Developer tab in the Ribbon check box, and then click OK.
  2. On the Developer tab, in the Controls group, click Insert, and then under ActiveX Controls, click Command Button Button image.

    Controls group

  3. Click the worksheet location where you want the upper-left corner of the command button to appear.

  4. In the Controls group, click View Code.
    This starts the Visual Basic Editor. Make sure that Click is selected in the dropdown list on the right. The sub procedure called CommandButton1_Click, as shown in the following picture, runs two macros when the button is clicked.

Source

Now just repace the code of the CommandButton1_Clickwith the code inside the sub which I've posted on top of this.

Christian

Posted 2013-10-25T07:36:25.880

Reputation: 6 571