FormulaCraft

How to use cell references inside QUERY criteria in Excel and Google Sheets

Topic:QUERY (Google Sheets SQL)

Heads up: Excel and Google Sheets do this differently.

Excel
=FILTER(A2:C10,B2:B10=E2)
Google Sheets
=QUERY(A1:C10,"SELECT A, B, C WHERE B = '"&E2&"'",1)

Try it with your data

Edit the grid or formula, then run it through a real spreadsheet engine — no signup.

Sample data — click any cell to edit

Runs server-side · free · no signup

Step by step

  1. 1Type your filter criterion in a standalone cell — for example, put 'North' in E2 so users can change it without editing the formula.
  2. 2In your destination cell, start the QUERY formula: =QUERY(A1:C10,
  3. 3Add the query string with concatenation: "SELECT A, B, C WHERE B = '"&E2&"'". The single quotes inside the string wrap the cell value for text comparisons.
  4. 4Close the formula with the headers argument: ,1).
  5. 5For numeric criteria omit the single quotes: "SELECT A, B, C WHERE C > "&F2, where F2 holds a number like 1000.

Tips

Need the Google Sheets version instead? Open Sheets variant in workspace →

Working on a sheet you inherited? Run the Auditor on the whole file first — it flags every #REF!, #N/A, broken column pattern, and inconsistent formula in seconds, free, no signup.

Frequently asked

Why does my QUERY return an error when I reference a cell with text?

You most likely forgot the single quotes around the cell reference inside the query string. Use 'WHERE B = '"&E2&"'' (note the single quotes flanking the concatenated cell value).

Can I reference a range of cells for an IN-style filter?

QUERY does not have an IN operator. To filter against a list in E2:E5, build the OR string dynamically with a helper formula like TEXTJOIN(" OR B = '",TRUE,E2:E5) and concatenate that into the WHERE clause.

Does the same concatenation pattern work for QUERY with IMPORTRANGE?

Yes. Wrap the concatenated query string around IMPORTRANGE exactly as you would for a sheet range: =QUERY(IMPORTRANGE("url","Sheet1!A:C"),"SELECT Col1 WHERE Col2 = '"&E2&"'",1).

More on QUERY (Google Sheets SQL)

See all →

Formulas used

Related tasks

Written and reviewed by FormulaCraft Team. Each formula on this page is run through our verification engine before publishing.

Last reviewed: