Using IMPORTRANGE as an array formula

时光毁灭记忆、已成空白 提交于 2021-02-18 17:51:07

问题


I have a URL in one cell which is the criterion for the IMPORTRANGE. e.g.:

=IMPORTRANGE(B2,"sheet1!$A$1")

I found a formula to collect it as criterion, but not in array version.

A sample can be found here.


回答1:


I see you have column B filled with Spreadsheet Ids, and you are trying to execute

=ArrayFormula(IMPORTRANGE(B2:B,"sheet1!$A$1")) 

Not every spreadsheet function supports arrays as argument. In particular, importrange does not. You need separate importrange formulas for separate spreadsheets you are importing.

Indeed, importing data from another spreadsheet is not a batch operation; each import has to be authorized by clicking a prompt the first time it's called. Also, it's a very slow operation; you will get a serious performance hit if trying to import a lot of other spreadsheets.

Generally, if you find yourself doing a lot of importrange, it may be time to rethink the overall data organization.




回答2:


While you cannot use IMPORTRANGE() in an arrayformula, as detailed in the other answer, you can use it in an array literal. In your case, for the first five cells in your column B that contain spreadsheet URLs:

={
  IMPORTRANGE(B2,"sheet1!$A$1");
  IMPORTRANGE(B3,"sheet1!$A$1");
  IMPORTRANGE(B4,"sheet1!$A$1");
  IMPORTRANGE(B5,"sheet1!$A$1");
  IMPORTRANGE(B6,"sheet1!$A$1")
}

So you'll have to write IMPORTRANGE() multiple times and you can only use this technique if you know before how many sheets there are to import. But the advantage is that this also works where IMPORTRANGE() returns multiple rows each – in that case, copying the formulas down is no option, as IMPORTRANGE() creates an error in cases where its results would overwrite cell contents further down.



来源:https://stackoverflow.com/questions/41504050/using-importrange-as-an-array-formula

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!