Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a query in an Excel table. I followed this to do it.

But how can I add a parameter from a cell into my query?

I am looking for a way to do this:

select *
from dbo.Customers
where CustomerID = Cell.A2

The Cell.A2 does not work. But how can I add in something like it, so that the contents of a cell are used in my query?

share|improve this question
Have you tried just naming the cell - then using the name in the query instead of the cell reference? – user441167 Apr 25 '15 at 15:39
up vote 11 down vote accepted

Dunno why MS has made this so complicated, You will have to use Microsoft Query.

Click on Data -> From External Sources -> From Microsoft Query. CHoose Data source comes up. Select SQL Server, enter the Auth details, and select the table

enter image description here

Click on Next, don't select any filtering criteria, choose sort by criteria, click on next. Now, click on View/Edit in MS Query instead of selecting Return to Excel

enter image description here

Click on Finish. Now in MS Query, Click on Criteria -> Add Criteria, choose the operator and let the value be []

enter image description here

Click on File -> return data to Excel. Now Excel should prompt you for the parameter, select the relevant cell

enter image description here

To edit the parameters, click on Data -> Properties -> Finger icon -> Definition -> parameters

enter image description here

You can also use the SQL query editor and type in the query with the joins and put a ? against the field where the parameter has to be fetched.

enter image description here

share|improve this answer
Alas, parameters is disabled. – Vaccano Oct 11 '10 at 16:34
@Vaccano: Revamped my answer, please have a look – Sathya Oct 11 '10 at 17:37
Thanks for the effort on this Sathya. Alas I realized that because my query has some joins in it MS Query cannot display it graphically. That makes it so you cannot have parameters. I am going to make it as a VBA function. I am giving you the nod though because your answer was so complete. – Vaccano Oct 11 '10 at 18:09
@Vaccano: You can write the query using the SQL editor, and put a ? against the field to which the parameter has to be selected – Sathya Oct 11 '10 at 18:30
I have found that once the query is in Excel, you can go into the query parameters screen and edit it there without going into MS Query again. Just drop a ? where the criteria goes. Then go back into the connection properties screen and assign that parameter to a cell in the spreadsheet. – Tracy Probst Nov 1 '10 at 14:33

Put value as

where employeecode = '?'

This will enable your parameter button, but when you press ok it will prompt you.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.