• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Generate CSV file from a filtered data list

inddon

Member
Hello There,

I came across a sample code to create csv file from a selected range as below (hopefully this could be useful for others):

I would like to make this work where it generates a csv file only for the filtered data list.
Could you please help in adjusting the VBA code and make this work for my requirement?

I have attached a sample workbook which contains the sample filtered data and also the above reference VBA code.

Thank you and look forward to hearing from you.

Regards,
Don
 

Attachments

  • Sample workbook Filter Data to CSV.xlsm
    27.9 KB · Views: 3
Possibly...
Code:
Sub CSV_test()
    Dim wb As Workbook, rg As Range
    Set wb = Workbooks.Add
    With Sheet1.Cells(1, 1).CurrentRegion
        Set rg = .SpecialCells(xlCellTypeVisible)
        rg.Copy wb.Sheets(1).Cells(1, 1)
        wb.SaveAs Filename:="E:\Test1.csv", FileFormat:=xlCSV
    End With
End Sub
 
Thank you for your reply.

The solution stated in my original post does not involve adding a new workbook for making a csv file.
It works fine but it does not work for filtered data. The Author's code needs to be adjusted to work for filtered data.

Regards,
Don
 
The code works as it should on your sample workbook. Run your filter and then run the code. Only filtered data is copied to the new csv workbook.
 
Back
Top