12

Document 1 has many rows of data.

How do I import into document 2 only those rows that have a certain value in column C?

15

Basics:

This is not as straight forward as a normal import using the IMPORT function. With this function, you are able to perform imports only:

=IMPORTRANGE("key","range")

Adding a function, like SUM or FILTER, within the "range" string will result in an error. The solution must be found, by using the QUERY function:

=QUERY(IMPORTRANGE("key","range"),"SELECT * WHERE Col1='value'")

OR

=QUERY(IMPORTRANGE("key","A:Z"),"SELECT * WHERE Col1 contains 'value'")

NOTE:

After WHERE, Column definition must be as first letter upper-case then lower case. Col will work, COL or col will not.

Ordering:

Once imported you can order the results by using the ORDER BY clause:

=QUERY(IMPORTRANGE("key","A:Z"),"SELECT * WHERE Col1 contains 'value' ORDER BY Col1")

Select columns:

So the IMPORTRANGE function cannot do selected columns, it can only do one range block. The way around this is to use the QUERY function SELECT clause:

=QUERY(IMPORTRANGE("key","A:Z"),"SELECT Col1, Col2, Col3 WHERE Col1 contains 'value' ORDER BY Col1")

References:

  • 1
    @user2338585 Please mark the answer, so that future visitors will notice !! Good luck. – Jacob Jan Tuinstra May 9 '13 at 17:50
  • hey @Jacob - thanks so much! that's an amazing writeup... I am trying to do something very similar to this, but with ONE extra step... I want the selection of the master data to to be set via the value of a cell in the target spreadsheet... ie in target sheet's column A, row 2 I have a value (say 1000023) and I want column values from the matching row in the source spreadsheet to be imported... Tried using cell A2 in your select columns example, using lots of different combinations to refernce it. Frustratingly when I edit my formula it SHOWS A2's value when highlighted, but won't use it.. – Julian Higginson Jun 21 '16 at 2:50
3

Had this same issue: This is what I ended up using.

=iferror(QUERY(IMPORTRANGE("https://docs.google.com/spreadsheets/d/[YOUR_KEY_FROM_URL]/edit","Title of Sheet You are Using!A2:I42"),"select * WHERE Col5 CONTAINS 'Towel'",1),"no values yet!")

Lets break it down a bit

IFERROR allows you to display a user friendly message if this fail because no data is returned

QUERY allows you to specify the search criteria. You can omit this if you simply want to import the range of cell regardless.

IMPORTRANGE Use the url provided, then fetch this sheet, looking at these ranges (top left, to bottom right)

  • its important to note that IMPORTRANGE returns a 'mini spreadsheet' based on what you required: A2:I42. In this case 9 columns. Even if your original sheet has 20 columns, the query only has access to what columns are returned. So if the QUERY used Col12 it would throw an error because only 9 were returned. – roberthuttinger Oct 16 '18 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.