# Excel: passing a cell value to a SQL query

**URL:** <https://boards.straightdope.com/t/excel-passing-a-cell-value-to-a-sql-query/386573>\
**Category:** Factual Questions\
**Created:** [January 3, 2007, 6:32pm UTC](https://boards.straightdope.com/t/excel-passing-a-cell-value-to-a-sql-query/386573 "2007-01-03T18:32:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Engywook](https://avatars.discourse-cdn.com/v4/letter/e/bc8723/32.png) [@Engywook](https://boards.straightdope.com/u/Engywook)\
**Post date:** [January 3, 2007, 6:32pm UTC](https://boards.straightdope.com/t/excel-passing-a-cell-value-to-a-sql-query/386573/1 "2007-01-03T18:32:29Z")

</div>

I’ve just begun working with SQL, and have been thinking that it would very much simplify my life when I’m working with Excel.

So I was very happy to discover that, when editing a OLE DB query of another Excel spreadsheet, you can use an SQL query.

So far, so good.

However, to really be useful, I need to be able to dynamically generate the query from cell values, not hard code it every time.

For example,  
SELECT \* FROM `Sheet1$` WHERE `Cell Value` = “Fred”;

But instead of using Fred, I’d want to pass the value of a cell.

Doesn’t seem to be working no matter what syntax I use to indicate the cell. Google showed one other guy who had exactly the same question I have… but you gotta pay for the answer.

C’mon, there’s gotta be a way to do this, right?

Extra points if the solution doesn’t involve any VBA.

---

<div class="post-metadata">

**Author:** ![CookingWithGas](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/cookingwithgas/32/485_2.png) [@CookingWithGas](https://boards.straightdope.com/u/CookingWithGas)\
**Post date:** [January 3, 2007, 7:09pm UTC](https://boards.straightdope.com/t/excel-passing-a-cell-value-to-a-sql-query/386573/2 "2007-01-03T19:09:58Z")

</div>

I don’t know how to do this without VBA but it might be possible. Where is it that this query appears?

[Here is the best place to ask.](http://www.ozgrid.com/forum/forumdisplay.php?f=8) Requires free registration.
