Filter CSV Data in Excel 2016 with Late-Binding ADO
Question details
Filter CSV records by a currency value in an Excel 2016 VBA application using late-binding ADO.

- Product
- Microsoft Excel 2016
- Device & OS
- not provided
- Scenario
- A VBA application queries a CSV file through ADO and needs to select records for a currency such as USD.
- Observed behavior
- SELECT * returns records, but the currency-filtered query fails with late binding even though an early-binding version works.
Confirm the CSV file name, folder, and exact currency column header. Keep your working ADO connection string handy and check that the text provider it uses is available to Excel.
Build the currency filter dynamically in VBA
Use this approach when the existing ADO connection can read the CSV but the filtered SQL query fails.
Late binding uses CreateObject instead of an ADO library reference. Text values in the SQL WHERE clause still need single quotes, and the variable must be concatenated into the query string.
In Excel, press Alt+F11 and open the module containing the CSV query. Keep the connection string that already works with SELECT *.
Replace the sample file and column names with yours. For example: currency = "USD" sql = "SELECT * FROM [rates.csv] WHERE [Currency] = '" & Replace(currency, "'", "''") & "'" Debug.Print sql Open View > Immediate Window to verify that the resulting WHERE clause contains a quoted value, such as [Currency] = 'USD'.
With your existing late-bound connection object open as conn, run Set rs = conn.Execute(sql). Check rs.EOF before reading records, then close the recordset and connection when finished.
Change the currency variable to GBP, EUR, or another value present in the CSV and run the macro again. If no records match, inspect the CSV header and values for extra spaces or spelling differences.

Import and filter the CSV with Power Query
Use Power Query when you want to filter and load CSV data without maintaining an ADO query in VBA.
Work with CSV data in WPS Spreadsheets
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface. Open CSV and Excel files to review and filter data, making it easy to move everyday spreadsheet work from Microsoft Office. It does not fix Excel's ADO or VBA configuration.

Frequently Asked Questions
Why does SELECT * work but the currency filter fail?
The connection may be working while the WHERE clause is malformed. Print the SQL with Debug.Print and check that the column name is correct and the text value appears in single quotes, such as [Currency] = 'USD'.
Do I need an ADO reference for late binding?
No. Late binding creates ADO objects with CreateObject, such as CreateObject("ADODB.Connection"), rather than requiring a VBA project reference. The underlying data provider still needs to be available.
How do I use a variable instead of a fixed currency?
Concatenate the variable into the SQL string and surround its value with single quotes. Use Replace(currency, "'", "''") to escape any single quotes in the value.
Can I filter the CSV without writing VBA?
Yes. In Excel 2016, use Data > Get Data > From File > From Text/CSV, select Transform Data, and apply a filter to the currency column before choosing Close & Load.




