Search code examples
google-sheetsgoogle-sheets-query

How to refer to a cell value when using a query


I am trying to populate columns C,D,E,L,K,M,N on a Google Sheets spreadsheet..

Below is my code but it returned a VALUE error when I ran it. Could someone please advice?

=QUERY(QUERY('BI_Keywords Raw Data'!$A:$C, "Select * WHERE B = """&B2&""" " ), "SELECT * OFFSET 1", 0)

enter image description here

Thanks a lot!


Solution

  • You have a mistake within the query syntax trying to connect it with the value in cell C2.

    To include a cell value in a query you need to use a combination of singe and double quotes like

    '"&A8&"'

    Single quote ' double quote " ampersand & cell A8 ampersand &double quote " single quote '

    Thus, your corrected query would be

    =QUERY(QUERY('BI_Keywords Raw Data'!$A:$C, "Select * WHERE B = ' "&B2&" ' " ), "SELECT * OFFSET 1", 0)