Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

I have a monthly spreadsheet that relies on figures from the previous month. I'd like to import these values dynamically rather than cutting and pasting them. Is this possible? How do I do it?

share|improve this question
    
By the way, I know this is possible as I did it once, but I can't find the information anymore or the sheet I did it in. If I find it, I'll post an update. –  Jeff Yates Jul 1 '10 at 15:32

6 Answers 6

up vote 64 down vote accepted

IMPORTRANGE() appears to be the function you want.

From the Google spreadsheets function list:

Google Spreadsheets lets you reference another workbook in the spreadsheet that you're currently editing by using the ImportRange function. ImportRange lets you pull one or more cell values from one spreadsheet into another. To create your own ImportRange formulas, enter =importRange(spreadsheet-key, range). For languages where comma is used for decimal separation, use a semicolon instead of a comma to separate arguments in your formula.

Spreadsheet-key is a STRING which is the key value from the spreadsheet URL.

Range is a STRING representing the range of cells you want to import, optionally including the sheet name (defaults to first sheet). You can also use a range name if you prefer.

Given that the two arguments are STRINGs, you need to enclose them in quotes or refer to cells which have string values in them.

For example:

=importrange("abcd123abcd123", "sheet1!A1:C10") "abcd123abcd123" is the value in the "key=" attribute on the URL of the target spreadsheet and "sheet1!A1:C10" is the range which is desired to be imported.

=importrange(A1,B1) Cell A1 contains the string ABCD123ABCD123 and cell B1 contains sheet1!A1:C10

Note: In order to use ImportRange, you need to have been added as a viewer or collaborator to the spreadsheet from which ImportRange is pulling the data. Otherwise, you'll get this error: "#REF! error: The requested spreadsheet key, sheet title, or cell range was not found."

"key" is of course the string in the URL for the spreadsheet that matches to the key= parameter.

I just tested it by creating two spreadsheets. In cell A1 of the first I put a string. In cell A1 of the second I put =importRange("tgR2P4UTz_KT0Lc270Ijb_A","A1") and it displayed the string from the first spreadsheet. (Your key will obviously be different.)

(The format of the function may depend on your locale. In France the formula is not valid with a comma, so you'll need to be replace it with a semi-colon: =importRange("tgR2P4UTz_KT0Lc270Ijb_A";"A1"))

NOTE: Google currently sets a hard limit of 50 "cross-workbook reference formulas" per spreadsheet. Source: Google Docs, Sheets, and Slides size limits. (h/t JJ Rohrer)

NOTE 2: The "new" Google Spreadsheet (soon to be the standard) removes the 50 limit of 50 "cross-workbook reference formulas (Google Support) (h/t Jacob Jan Tuinstra)

share|improve this answer
    
@Al: Yes! That's it! Thanks. –  Jeff Yates Jul 1 '10 at 16:21
    
+1 Whoa! I didn't realize there was an in-line version. The other option is to use Google Apps scripting. Create a function that uses SpreadsheetApp.openById([ID]).getRange() and set a local range with that. –  Evan Plaice Feb 16 '12 at 8:09
2  
It might be worth noting that you'll be limited to 50 of these (per spreadsheet?) (a hard Google limit): support.google.com/drive/answer/37603?hl=en –  JJ Rohrer Oct 10 '13 at 3:34
1  
In the new Google Spreadsheet (soon to be the standard), the 50 limit has been removed: support.google.com/drive/answer/3093340?hl=en –  Jacob Jan Tuinstra Apr 1 at 21:58
1  
Thanks, @Jacob. I've updated my answer. –  Al E. Apr 1 at 22:29

FYI if you want to reference another sheet within that other spreadsheet, the sheet name should NOT be re-quoted:

use

=importRange("tgR2P4UTz_KT0Lc270Ijb_A","Sheet Name!A1:A10")

instead of

=importRange("tgR2P4UTz_KT0Lc270Ijb_A","'Sheet Name'!A1:A10")

share|improve this answer
    
This is what caused me what too much stress. Thank you. –  F Oak May 8 '13 at 17:46
1  
Thanks. You should add this as a comment to other answer or even just edit that answer. –  studgeek Nov 1 '13 at 19:10

In the new interface, you should simply be able to type = in the cell, then just go to the other sheet and pick the cell you want. If you want to do it manually, or are using the old interface, you can simply do =Sheet1!A1, where Sheet1 is the name of the sheet, and A1 is the cell on that sheet you care about. This is identical to Microsoft Excel.

share|improve this answer
4  
if the sheetname has whitespaces in it, use 'This Other Sheet'!A1 –  akira Jul 1 '10 at 14:35
3  
What about from an entirely different document, as I asked in the question? –  Jeff Yates Jul 1 '10 at 14:46
    
@jeff Sorry; you didn't mention "document" in the body, and for some reason, in my head, I thought "sheet." As far as I know, you can't dynamically link to another document. But you could use multiple sheets, rather than multiple documents, at which point you could do what I suggested. This is how I run my own monthly finances, for precisely this reason. –  Benjamin Pollack Jul 1 '10 at 15:09
    
It's okay :) I know there's a way to do it as I've actually done it myself, but I've forgotten and I can't find the sheet I did it in. –  Jeff Yates Jul 1 '10 at 15:31

I found this syntax using Insert -> Define new range RANGE FOR REFERENCING OTHER SPREADSHEET:

Whole A column: 'Spreadsheet With Spaces in the name'!A:A

Whole B column: 'Spreadsheet With Spaces in the name'!B:B

etc.

Then you can use it as:

=COUNTIF('First Page'!B:B, "valueToMatch")

share|improve this answer
    
Is this also possible for referencing outside the spreadsheet? –  Jacob Jan Tuinstra Dec 30 '12 at 20:11
    
@JacobJanTuinstra what do you mean 'outside' the spreadsheet? –  Tom Roggero Dec 31 '12 at 13:51
1  
Well, the IMPORTRANGE function can import data from another spreadsheet. Setting ranges is only meant (possible) within a spreadsheet. That's what I meant with outside. –  Jacob Jan Tuinstra Dec 31 '12 at 14:11

here is how i did it (reimplemented 'importrange()'):

  • open the script editor ("tools" -> "scripts" -> "script editor")
  • provide a function like this (without any checks, this has to be improved but you get the general idea):
function REMOTEDATA(inKey, inRange) {

  var outData;  
  var ss = SpreadsheetApp.openById(inKey);

  if (ss) {
     outData = ss.getRange(inRange).getValues();
  }

  return outData;
}
  • use this formula like this in your spreadsheet:
=SUM(REMOTEDATA("key", "SheetName!A1:A10"))

"key" is the key of the document, you find it in the "key=xyz" parameter of the document url.

the documentation for 'spreadsheet services' provides more information on the topic.

share|improve this answer
2  
What would be the advantage of implementing this yourself rather than using the existing function? –  Jeff Yates Jul 1 '10 at 16:22
    
@Jeff Yates: none, i just implemented it without knowing importrange(). sportsmanship, you know? all in the way of just- because-i-can :) –  akira Jul 1 '10 at 18:45

I did it very easy way by using Query for example I have 2 sheets ABC and XYZ and I want to import range from A1 to C30 from Abc into XYZ, click the cell where you want the range to be appear and write this:

=QUERY(ABC!A1:C30)

Note: If your sheet name have spaces then of course you write this:

=QUERY('ABC 1'!A1:C30)

share|improve this answer
5  
The OP asked how to import cells from another document. Can QUERY do that? –  Vidar S. Ramdal Nov 6 '12 at 14:08
    
@VidarS.Ramdal It can, but it needs importrange("abcd123abcd123", "sheet1!A1:C10") e.g., =query(importrange("abcd123abcd123", "sheet1!A1:C10")) ;-) –  Fuhrmanator Jun 2 at 18:05

protected by Community Dec 30 '12 at 23:11

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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