Google Sheets QUERY Function Cell References Explained

How-to basics · Updated December 3, 2026

In Google Sheets, a cell reference used inside a QUERY formula identifies the source data range; references inside the query text are written as column identifiers such as A, B, or Col1, not as ordinary A1 references. To make the queried range dynamic, put its reference in the first argument, for example =QUERY(A1:D100,"select A, D where B = 'Open'",1).

What a cell reference means in QUERY

The function takes a range or array as its data argument, then applies a query-language string to that data. Its usual structure is QUERY(data, query, [headers]). The first argument is a normal Sheets range reference, such as A1:D100 or Data!A:D. The second argument is text describing which columns to return, filter, group, or sort.

This distinction is the source of many mistakes. In QUERY(A1:D100,"select A where B = 'Open'",1), A1:D100 is a spreadsheet reference, while A and B are column labels interpreted by the query language. The query string is not a regular Sheets formula, so putting A2 in it does not automatically mean “use the value in cell A2.”

Column letters and Col numbers

When the data argument is a range of cells with standard sheet columns, query expressions can use the corresponding column letters. For example, if the range is A1:D100, the columns are referred to as A, B, C, and D. If the range begins elsewhere, its original sheet column labels remain meaningful: a range such as C1:F100 can use C through F.

For data assembled as an array, or where letter labels are inconvenient, use identifiers such as Col1, Col2, and Col3. These identify positions within the supplied data, starting at the first column of that data. For instance, with data in A2:C100, Col1 corresponds to sheet column A, Col2 to B, and Col3 to C. Being explicit with Col labels is especially useful when the input is a constructed array rather than one contiguous range.

Use a cell value as a filter

To make the criterion change when a user edits a cell, join that cell’s value into the query string. Suppose a table has status values in B2:B100, and the selected status is in F1. With the full table in A1:D100 and a header row, use:

=QUERY(A1:D100,"select A, B, D where B = '"&F1&"'",1)

If F1 contains Open, the resulting query text is equivalent to select A, B, D where B = 'Open'. The single quotation marks around the text criterion belong inside the query string; the ampersands join the text fragments and the cell value. For a numeric criterion in F2, quotation marks are generally not used around the number:

=QUERY(A1:D100,"select A, D where D > "&F2,1)

Here, D must contain values QUERY recognizes as numeric, and F2 should contain a number. Text and dates require different care: text criteria use single quotes in the query language, while date literals use the query language’s date syntax, for example date '2026-01-15'. If a date is supplied from a cell, it may need to be formatted into that required text form rather than concatenated as the sheet’s displayed date.

Make the source range dynamic

A range can be fixed, open-ended, or selected through a cell reference. An open-ended range such as A:D includes future rows added in those columns, which can be convenient for growing tables. A bounded range such as A1:D1000 can reduce unnecessary scanning in very large sheets, but new rows beyond its endpoint will not appear. Choose a range that matches how the data is maintained.

If a cell contains a sheet name or range address as text, a normal reference will not interpret that text as a reference. Google Sheets provides INDIRECT to convert reference text into a reference, such as =QUERY(INDIRECT("'"&F1&"'!A:D"),"select A, B",1), where F1 contains a valid sheet name. This is more flexible but can be harder to troubleshoot; the sheet name must exist, and names with spaces need single quotes around them as shown.

For a straightforward query that should always use the same source, a direct range is usually clearer. Use INDIRECT only when the reference itself genuinely needs to change based on an input.

Headers, quoting, and data types

The optional third argument tells QUERY how many header rows are at the top of the data range. Use 1 for one header row, 0 when there are none, or another appropriate count if the range has multiple header rows. If omitted, Sheets tries to infer the number, and inference may not match the layout you intended. A wrong header count can cause a heading to be treated as data or the first data row to be treated as a heading.

Query syntax also has its own quoting rules. Text values in conditions are enclosed in single quotes inside the query string. A column name containing spaces or special characters may need to be enclosed in backticks, such as `Order status`, when using a header name in a query expression. If a cell value itself contains an apostrophe, simply joining it into a quoted condition can break the query; sanitize or redesign the input rather than assuming all arbitrary text can be inserted safely.

QUERY determines a data type for each column. A column containing a mixture of numbers and text may have values of the minority type treated as null in query results. Keep each column consistent where possible, and check whether imported numbers or dates are actually stored as numbers or dates rather than text.

Common reference errors and fixes

  • Using A1 inside the query string: where B = F1 is not a normal cell-reference comparison. Join the value from F1 into the query text, or use a different formula approach.
  • Wrong column identifiers: Check which columns are included in the data argument. With an array or a range whose layout has changed, Col1 may not represent the sheet column you expect.
  • Missing quotation marks: Text conditions need single quotes in the query language, while the entire query expression is enclosed in double quotes as a Sheets string.
  • Incorrect header count: Set the third argument explicitly when the input has a known number of header rows.
  • Range stops too early: Expand a bounded range or use an open-ended range if new records must be included.
  • Numbers or dates behave like text: Confirm the underlying cell values and make the column’s data type consistent before changing the query.

When an error appears, first test the query with a fixed value and a small known range. Once that works, add the cell reference and expand the data range. This isolates whether the issue is the query syntax, the concatenation, or the source data.

Frequently Asked Questions

Can I put a cell reference directly inside the QUERY string?
No. The query is text, so a reference such as F1 is not evaluated there as a cell. Join the cell’s value into the string with &, or use a formula designed to handle the condition another way.

Should I use A, B, or Col1 in a QUERY formula?
Use the identifiers that match the data argument. Letter labels are convenient for ordinary sheet ranges; Col1 and related labels are useful for array data and position-based references. Check the range’s starting column and layout before choosing.

How do I reference a cell on another sheet?
Use a normal cross-sheet reference for the data argument, such as Data!A1:D100. If the sheet name contains spaces, enclose it in single quotes: 'Sales Data'!A1:D100. To query a range selected by a sheet name stored in a cell, use INDIRECT carefully.

How do I use a drop-down cell as the QUERY filter?
Put the drop-down in a cell such as F1, then concatenate F1 into the query condition. Ensure the query uses the correct quotes for the selected value’s type; a text selection needs single quotes in the query expression.

Does QUERY use the same references in Excel?
No. QUERY is a Google Sheets function and its query-language syntax is not an Excel feature. Excel has other tools and functions for filtering and querying data, but a Google Sheets QUERY formula cannot simply be copied into Excel unchanged.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.