google sheets – How to use use cell references in the WHERE part of a QUERY / IMPORTRANGE formula

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 '.