Skip to content
Advertisement

Dynamically Using Sheetname in Sql-VBA

Sheet1, i.e. the name of the sheet in my case is variable in my case and I want to repeat this query for 100 sheets, so how do I dynamically specify the name?

Thanks in advance.

Advertisement

Answer

First, you cannot call an entire worksheet in an Excel SQL ADO query but must specify ranges: SELECT [Sheet1$A1:D50].ID FROM [Sheet1$A1:D50] WHERE [Sheet1$A1:D50].ID IS NULL

And yes, since this is a string statement you can concatenate VBA variables within it.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement