Google Sheets IMPORTRANGE and QUERY

225 Views Asked by At

I'm new to Sheets and the query function as of last night, so don't know the terminology etc - sorry!

I have two workbooks, a master and a template. I need the templete to pull specific data from the master when Col2 matches a particular number. I have it working great if i manually input the number, but don't want to have to do this everytime I give a copy of the template to a new job. This number in Col2 is unique to each of the templates I give to a new job, and the number will already be manually input into cell J16 of the template. I want the code to pull the number from J16 and search rather than me telling it what the number is everytime. The code I have that works with the manual input number, in this case 4032 is below. Thanks in advance for any help.

Vince.

=QUERY(IMPORTRANGE("1yTp3SajbKovHf_Wjx7CHO9FsIPeQGvmdMytQIkr9gog","Invoices"),"select Col1, Col5, Col11 where Col2 = 4032")

1

There are 1 best solutions below

1
On

Do you want to get the number (any) from J16 into your query?

Use:

=QUERY(IMPORTRANGE("file_id","Invoices"),"select Col1, Col5, Col11 where Col2 = " & J16)

or better:

=QUERY(IMPORTRANGE("file_id","Invoices"),a1)

where a1 is:

="select Col1, Col5, Col11 where Col2 = " & J16