Do column names need to be in Row 1 for SQL queries to work?

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Thanks to your Addin I’ve been executing SQL statements now for the last 3 months like they’re going out of style (thank you). Now I’ve run into a small problem that I need to ask about. I have a workaround for this but just in case there’s a more elegant solution I thought I’d put it out there.

I’m attempting to select certain columns from a sheet where many of the column names are on line 2 (deliberate design). I pass:

“SELECT [Initiative], [Yr], [Qtr] FROM [Scheduler$]”

to the ExecuteSQL function and it gives me an error saying I haven’t passed enough parameters. These particular column names are on row 2 and I think that’s why the function fails. I’ve looked at the code but can’t see a way to point the function to another row for header information (it would probably be messy if it did). I can SELECT all columns and just delete the ones I don’t want but I was hoping for a more elegant solution.

Any ideas?

Thank you in advance…..


That depends.

Probably you have some data in the first row. In a newly created sheet the column names can as well be in the second row.

So this should then work in a NEW worksheet where all data starts at row 2:

Otherwise you need to use column names:

F1 – is the first column, and so on. Problem would be with removing the first row of the query

selected as best answer

Simply the best place to learn Excel VBA