Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining multiple spreadsheets in one using IMPORTRANGE

I would like to aggregate the data of multiple spreadsheets into one spreadsheet.

  • Spreadsheet 1 has a Row of Strings A2:A500
  • Spreadsheet 2 has a Row of Strings A2:A500
  • Spreadsheet 3 is supposed to have a Row of both (Spreadsheet1!A2:A500 AND Spreadsheet2!A2:A500).

Duplicates shall not be handled differently. I would like them to appear as often as they appear in the different sheets.

Is it possible to do this without writing a script or using jQuery, e.g. by using IMPORTRANGE?

What does not work: I have tried using IMPORTRANGE as follows:

ARRAY{IMPORTRANGE("key-of-spreadsheet1","list!A2:A500"), IMPORTRANGE("key-of-spreadsheet2", "list!A2:A500")}

This causes an error.

like image 587
FlorianT. Avatar asked Jul 27 '15 15:07

FlorianT.


People also ask

Can I use Importrange for multiple sheets?

IMPORTRANGE to import data from multiple Google sheets. As the name of the function suggests, IMPORTRANGE imports data from multiple Google spreadsheets into one sheet. Tip. The function helps Google Sheets pull data from another document as well as from other tabs from the same file.


1 Answers

Of course, it is also possible to combine several IMPORTRANGE() functions with the QUERY() function, which gives us a greater control over the results we import.

For example, we can use such a construction:

=QUERY(
  {
    IMPORTRANGE("key-or-url-of-spreadsheet-1", "'sheet-name-1'!A2:Z100");
    IMPORTRANGE("key-or-url-of-spreadsheet-2", "'sheet-name-2'!A2:Z100");
    IMPORTRANGE("key-or-url-of-spreadsheet-3", "'sheet-name-3'!A2:Z100");
    IMPORTRANGE("key-or-url-of-spreadsheet-4", "'sheet-name-4'!A2:Z100")
  },
  "SELECT * WHERE Col1 IS NOT NULL ORDER BY Col3 ASC"
)

###Explanation:

The above query removes blank lines from imported ranges:

SELECT * WHERE Col1 IS NOT NULL

and sorts ascending all data collected together in relation to the third column:

ORDER BY Col3 ASC

For descending, just use DESC in place of ASC.

Of course, we can also arrange any other criteria, or omit them displaying everything without modification:

"SELECT * "

###Note:

In order to use the above constructed query, we first need to call a single IMPORTRANGE() method for each of the spreadsheets we want to refer:

=IMPORTRANGE("key-or-url-of-spreadsheet-1", "'sheet-name-1'!A2:Z100")

We have to do this even if we refer to the same spreadsheet in which we write this formula, but for every spreadsheet it is enough to do it once.

This is to be able to connect these sheets and allow access to the sheets (to which we have the access rights anyway):

                                                    enter image description here

After giving permission for all spreadsheets, we can use the above query.

like image 120
simhumileco Avatar answered Oct 14 '22 16:10

simhumileco