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.
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.
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
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.