Sub topic 13
Pulling Data from Another Spreadsheet with IMPORTRANGE
Assume you can open and edit Google Sheets, enter values, and use basic formulas. You should also understand A1 notation, where A1 means column A and row 1. This chapter shows how to reference data stored in a different spreadsheet file.
What IMPORTRANGE does
IMPORTRANGE imports a range of cells from one Google Sheets file into another. The destination spreadsheet displays the imported values, but the source spreadsheet remains separate.
The function has two arguments:
=IMPORTRANGE("spreadsheet_url_or_id","range_string")The first argument identifies the source spreadsheet. You can use its full URL or its spreadsheet ID. The second argument names the sheet and range to import.
For example:
=IMPORTRANGE("https://docs.google.com/spreadsheets/d/SPREADSHEET_ID","Sheet1!A1:C10")This imports cells A1 through C10 from the Sheet1 tab of the source spreadsheet.
You can also use a spreadsheet ID:
=IMPORTRANGE("SPREADSHEET_ID","Sheet1!A1:C10")The ID is the text between /d/ and the next slash in a Google Sheets URL.
Allowing access the first time
When you enter an IMPORTRANGE formula for a new source spreadsheet, Google Sheets usually displays a #REF! error with an option to allow access. Select Allow access. This creates permission for the destination spreadsheet to read the source spreadsheet.
Your Google account must have access to the source file. If the source file is private and your account cannot open it, allowing access will not work.
Choosing the source range
The range string uses this form:
SheetName!StartCell:EndCellIf the sheet name contains spaces, put the name in single quotation marks:
=IMPORTRANGE("SPREADSHEET_ID","'Sales Data'!A1:C10")You can import a single cell:
=IMPORTRANGE("SPREADSHEET_ID","Summary!B2")You can import an entire column from a starting row:
=IMPORTRANGE("SPREADSHEET_ID","Orders!B2:B")A large or open-ended range can import more data than needed. Prefer a bounded range when you know the expected size. Use an open-ended range when new rows should be included automatically.
Understanding refresh and errors
The destination normally refreshes when the source changes, but updates may not appear instantly. Large ranges and chains of imported data can also make a spreadsheet slower.
| Error | Common cause | First check |
|---|---|---|
| `#REF!` | Access has not been allowed, or the source range is invalid | Select Allow access and check the sheet name |
| `#N/A` | The requested data cannot be found or is unavailable | Check the source file and range |
| `#VALUE!` | An argument has the wrong type or contains malformed text | Check the URL and range string |
A sheet rename can break a reference if the range string still uses the old name. Changing the source spreadsheet's file location does not normally change its ID, but deleting or losing access to the file prevents the import from working.
Data flow
Use imported data in another formula
IMPORTRANGE returns a range, so another function can process it. For example, this formula totals column C from the source:
=SUM(IMPORTRANGE("SPREADSHEET_ID","Orders!C2:C"))For readability, place the imported range in a separate tab and refer to that local range in other formulas. This avoids repeating the same long URL and makes permission problems easier to locate.
Exercise
Write a formula that imports cells A2:D50 from the Data tab of another spreadsheet whose ID is ABC123.
Show answer
=IMPORTRANGE("ABC123","Data!A2:D50")