I'm creating a macro that queries a CSV file that a user chooses, and saves the result of only the lines that meet a certain criteria.
The CSV file contains 7 columns, but 2 of which the headers are dates so they vary. I need a way to be able to either find out the header names before running the query, or specify in the query through a header number.
My file contains the following CSV file:
Below is my code
objConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & dSource & ";" & _
"Extended Properties=""text;HDR=Yes;FMT=Delimited(,)"";Persist Security Info=False"
SqlQry = "SELECT * FROM " & dfile & " " & _
"WHERE ([% Change] >= 5 OR [% Change] <= -5) "
Rcdset.Open SqlQry, objConn
For i = 0 To Rcdset.Fields.Count - 1
data_ws.Cells(1, i + 1).Value = Rcdset.Fields(i).Name
data_ws.Cells(2, 1).CopyFromRecordset Rcdset
So basically I'm looking for anything that has a 5% change, and I also need to look for any that didn't have data on today's column. So in this case, it would be WHERE 1/2/2013 = '' but how can I chose this column/header when the value is constantly going to change?