.CSV from filtered table with VBA

CorneGeyser

New Member
Joined
Aug 13, 2019
Messages
10
Hi All,

I have a sheet that gets data via a query from the server. The aim is to filter for the info needed and having a 'Generate' button to create a separate .csv file for only the filtered data.

The issues I have are the following:
1. I am new to VBA, I currently have some autofilter code to filter the project I desire from the table.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim tabl As String, i As Long, C As Range
tabl = "TR_TEST_FOLDER" 'Name of the Table
If Not Application.Intersect(Range(Target.Address), Range("E2")) Is Nothing And Target.Count < 5 Then
    For Each C In Target
        tCol = Range("TR_TEST_FOLDER[[#Headers],[Project]]").Column
        If C.Value2 = "" Then
            ListObjects("TR_TEST_FOLDER").Range.AutoFilter Field:=1
        Else
            ListObjects("TR_TEST_FOLDER").Range.AutoFilter Field:=1, Criteria1:=C.Value2
        End If
    Next C
End If
End Sub
2. I need to include the code to generate the .csv with the code above. I have come across some VBA solutions for creating .csv files but not in my specific case to help me understand the combination of the two better.
3. Lastly, when generating the . csv file, it includes all the data in my table instead of what I have filtered for.

Screenshot of my table. Cell E2 is used for the autofilter.

1619086277963.png
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,214,985
Messages
6,122,605
Members
449,089
Latest member
Motoracer88

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