Google Sheets Query – Using Cell References in QUERY/IMPORTRANGE Formula

google sheetsgoogle-sheets-queryimportrange

Can you tell me what's wrong with my formula?


= QUERY (IMPORTRANGE ("url googlesheets database"; "Data range"); "SELECT Col1 
WHERE Col1 =" A3 "AND Col2 =" B3 "")

The "A3" and "B3" are cells in the active Google Sheets.

Best Answer

The second parameter of the QUERY functions is not using the correct syntax to concatenate values.

Instead of

"SELECT Col1 WHERE Col1 =" A3 "AND Col2 =" B3 ""

if Col1 and Col2 holds only number values use

"SELECT Col1 WHERE Col1 ="& A3 &" AND Col2 ="& B3 

if Col1 and Col2 holds only text values use

"SELECT Col1 WHERE Col1 ='"& A3 &"' AND Col2 = '"& B3 &"'"

NOTES:

  • & is the concatenate operator.
  • QUERY requires that text values be enclosed using '.