Google-sheets – How to get data from one Google Spreadsheets “A” into Spreadsheets “B”

google sheetsgoogle-sheets-queryimportrange

How do I get data from one Google spreadsheet A into spreadsheet B so
when Spreadsheet A is modified, then Spreadsheet B also changes automatically?

A formula using QUERY() and IMPORTRANGE() functions was tried, but it didn't return the expected results. For example, I have two spreadsheets Documents DocA and DocB:

    A               B           C
1    uid            serial_no   ph
2   356307042189331 3123958     912345678900
3   356307046077540 3966305     923451245123
4   356307046092465 3966407     978458784578
5   356307046098678 3970932     971548745125

In DocB

    A               B
1   serial_no      uid
2   3123958
3   3284728
4   3284655

I am trying to get A2 from DocA into B2 in DocB with the following formula

=QUERY(
     ImportRange("[key]","Sheet1!A:C"),
     "Select Col1, Col2 where Col1='"&A2&"'",
     1
 )

I get uid serial_no in Cell B2 instead of the value in Cell A2 of DocA.

Best Answer

Use the ImportRange function (documentation):

=IMPORTRANGE("spreadsheet key"; "Range")

See these example spreadsheets (A and B), which you may copy to your own Google Drive (File → Copy).