How to Use Cell Reference in Formula using Query function

Using cell references in a formula with the query function in Google Sheets allows you to make your query more dynamic, so you can easily change the data being queried without having to manually modify the formula itself. To use a cell reference in a query function, you need to use the INDIRECT function, which returns the value of a cell specified by a text string.

Example

Let's say you have a dataset in the range A1:D10, and you want to use the query function to filter the data based on a value specified in cell F1. Here's how you can use the cell reference in the formula:

  1. Open your Google Sheets document or create a new one.
  2. Enter your dataset in the range A1:D10.
  3. In cell F1, enter the value you want to filter the data by.
  4. In another cell, such as G1, enter the following formula:
=QUERY(A1:D10, "SELECT * WHERE B = " & INDIRECT("F1"))

In this example, the query function will filter the data in the range A1:D10 based on the value in cell B that matches the value in cell F1. The INDIRECT function is used to reference the value in cell F1, which is concatenated with the query string.

You can update the value in F1, and the query function will automatically update the results based on the new value.

Remember to adjust the range, criteria, and cell references according to your specific dataset and requirements.

Did you find this useful?