Yes, Google Sheets QUERY can reference named columns (named ranges) directly in the SQL-like statement, but with a catch: you must use the named range’s name in place of the sheet range (e.g., =QUERY(NamedRange, "SELECT *")), and inside the query string you still refer to columns by their column letters (A, B, C) or by the header labels you defined, not by the named range’s column names. This article explains exactly how to set it up, common errors, and how it differs from Excel.
What QUERY Actually Does with Named Ranges
The QUERY function in Google Sheets runs a Google Visualization API query on a data range. When you type a named range as the first argument, Sheets treats it as a valid data source, just like a sheet reference such as A1:C50. The named range must cover the entire data block you want to query, including headers. The query string itself uses the column letters of that range, not the names you gave the columns. For example, if you named the range SalesData covering A1:C50, you write:
=QUERY(SalesData, "SELECT A, B WHERE C > 100")
This returns columns A and B from the named range where column C is greater than 100. The named range simply replaces the cell reference; it does not rename columns inside the query.
How to Create a Named Range for QUERY
To use a named range with QUERY, first create it:
- Select the cells you want to include (e.g., A1:C50).
- Go to Data > Named ranges.
- Type a name (e.g.,
SalesData) and click Done. - In a cell, type
=QUERY(SalesData, "SELECT *").
That’s the simplest use. The named range can be on any sheet in the same spreadsheet. If the named range is on another sheet, QUERY still works as long as the name is unique.
Using Column Headers Inside the Query String
You can also reference columns by their header text, but you must enclose them in backticks (`) and use the Col1, Col2 syntax if you want to avoid header names. Actually, the QUERY language supports two ways:
- Column letters:
SELECT A, B– straightforward. - Header labels:
SELECT `Sales Amount`, `Region`– only works if the header text is exactly the same and you use backticks.
If you use header labels, the query string becomes case-sensitive and must match exactly. For example, if your header is “Sales Amount” (with a space), you write SELECT `Sales Amount`. This is independent of the named range; it works even with a plain range reference.
Why Named Ranges Break When You Add Rows
A common misconception is that a named range automatically expands when you add data below it. By default, a named range has a fixed size. If you add a row below row 50, the named range SalesData still only covers rows 1-50. To include new rows, you must edit the named range and extend the range, or use a dynamic named range with an open-ended reference like SalesData!A1:C (which refers to all rows in columns A through C). However, QUERY does not accept an open-ended range like A1:C directly; it expects a closed range. So you can either update the named range manually or use a formula that calculates the last row, but that gets complex. For most users, the simplest fix is to keep the named range large enough or update it when data grows.
Common Errors and How to Fix Them
When using named ranges in QUERY, you might see these errors:
- #NAME? – The named range doesn’t exist. Check spelling in Data > Named ranges.
- #VALUE! – The query string is invalid. Often because you used a header label without backticks, or you referenced a column letter that doesn’t exist in the range.
- #REF! – The named range is on another sheet and you used a sheet name that conflicts. Actually, named ranges are global, so this is rare. More likely, the range is empty.
- “Unable to parse query string” – You used a reserved word like
selectin lowercase? Actually, the query language is case-insensitive, but if you used a column label that contains a space without backticks, it will fail.
To debug, start with a simple =QUERY(SalesData, "SELECT *") and add clauses one by one.
Named Columns vs. Named Ranges: What’s the Difference?
In Google Sheets, there is no “named column” feature like in Excel tables. Excel has structured references like Table1[ColumnName]. Google Sheets only has named ranges, which can be a single cell, a row, a column, or a block. If you want to refer to a whole column by name, you can create a named range for that column (e.g., select A1:A100 and name it SalesAmount). Then you can use it in QUERY as the data source, but that would only query that single column, not the whole table. To query multiple named columns together, you’d have to combine them with {} or use a single named range covering all columns. So in practice, you use one named range for the entire table, and inside the query you refer to columns by letters.
Alternatives to Named Ranges in QUERY
If named ranges feel limiting, consider these alternatives:
- Use a separate sheet as a database – Keep your data on a sheet called “Data” and reference it as
Data!A1:Cin QUERY. This is simple and works well. - Use the FILTER function – For simple filtering,
=FILTER(A:C, C>100)is often easier and doesn’t require a query string. - Use QUERY with a full column reference – You can write
=QUERY(A:C, "SELECT A, B WHERE C > 100")but this includes the header row in the data, so you need to adjust withOFFSETor useWHEREto exclude headers. Actually, QUERY automatically treats the first row as headers, so it works fine. - Create a dynamic named range with OFFSET – You can define a named range using a formula like
=OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!$A:$A),3)to automatically expand. This is advanced but works.
Frequently Asked Questions
Can I use a named range inside a QUERY that references a cell containing the query text? Yes, you can put the query string in a cell (e.g., D1) and write =QUERY(SalesData, D1). This is useful for dynamic queries.
Why does my QUERY return a header row even when I don’t want it? By default, QUERY treats the first row as headers. To suppress headers in the output, add label clause or use OFFSET 1 in the query, but the simplest is to use =QUERY(SalesData, "SELECT *", 0) – the third argument (0) tells QUERY there are no headers, so it includes the first row as data.
Does QUERY work with named ranges that contain blank cells? Yes, but blank cells can affect calculations. For example, WHERE C > 100 ignores blanks, but if you use SUM, blanks are treated as zero. It’s safe to have blanks, but be aware of how they behave in aggregation.
Can I use a named range from another spreadsheet file? No, named ranges are local to one spreadsheet. To query data from another file, you’d need to use IMPORTRANGE first, then reference the imported range with QUERY.
Is there a limit to the number of named ranges I can use in a QUERY? No, but the total data size is limited by Google Sheets’ cell limits (currently 10 million cells). Each named range counts toward that limit.
How do I delete a named range? Go to Data > Named ranges, click the range name, and then click the trash icon. After deletion, any QUERY referencing it will return #NAME?.
Final Tips for Using QUERY with Named Ranges
To get the most out of this feature, keep these points in mind:
- Always include the header row in your named range, otherwise QUERY will treat the first data row as headers.
- Use
Col1,Col2syntax if you want to avoid header label issues:=QUERY(SalesData, "SELECT Col1, Col2 WHERE Col3 > 100")– this works regardless of header text. - When sharing a spreadsheet, named ranges are shared with editors, so collaborators can see and edit them.
- If you move the named range to another sheet, QUERY still works because the name is global.
With these techniques, you can make your QUERY formulas more readable and maintainable, especially in large spreadsheets where cell references become cryptic.
Related
- Google Sheets Query and Filter: How They Differ
- Table Saw Bevel Cut Jig: How to Make and Use One
- Forecast Equation in Excel: How to Build One
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- How to Track Changes in a Word Document and Review EditsTo track changes in a Word document, open it in Microsoft Word, select Review > Track Changes, then…
- Google Sheets QUERY ORDER BY: Sort Query ResultsIn Google Sheets, use the order by clause inside a QUERY formula to sort the rows it returns.…
- How to Wrap Text in Google Sheets Using a FormulaTo make text appear on separate lines inside a Google Sheets cell, insert a line break with CHAR(10)…
- Data Validation Shortcut Key in Excel: Windows and MacIn Excel for Microsoft 365 on Windows, press Alt, then A, then V, then V to open the…
- Excel Keyboard Shortcuts: What You Can Customize in ExcelIn Excel for Microsoft 365 on Windows, you cannot directly remap most built-in keyboard shortcuts through an Excel…
- Freeze Columns in Excel: Keep a Group Visible While ScrollingTo freeze a group of columns in Excel for Microsoft 365 on Windows, select the first cell to…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.