VBA & Macro Problems

Filter CSV Data in Excel 2016 with Late-Binding ADO

Maira MehtabMaira Mehtab Nov 22, 2026 868 views

Question details

Filter CSV records by a currency value in an Excel 2016 VBA application using late-binding ADO.

Filter CSV Data in Excel 2016 with 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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In Excel, press Alt+F11 and open the module containing the CSV query. Keep the connection string that already works with SELECT *.

2
Build and inspect the SQL

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

3
Execute the query

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.

4
Test other values

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.

Build the currency filter dynamically in VBA
Check the provider if the connection fails: If even SELECT * fails, check the installed ADO text provider and its compatibility with Excel's bitness. The SQL example assumes the CSV has a header named Currency.
Free Microsoft Office alternative

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.

Filter currency columns in a familiar spreadsheet interfaceOpen and edit Microsoft Excel XLSX files and CSV filesUse free, lightweight tools for everyday spreadsheet workMove existing spreadsheet files into a familiar Office-style workspace
microsoft office alternative - wps office

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.