Dynamic Sheet Name in Query in Google Spreashsheet

蓝咒 提交于 2019-12-12 07:27:55

问题


In Google spreadsheet I want to query data in another sheet but the problem is that the name of sheet is present in a cell. So is there a way in QUERY function to dynamically mention sheet name. Basically I am trying to do something like this but with dynamic sheet name:

=QUERY('2012'!A2:F;"select C, sum(F) where A='December' group by C order by sum(F) desc")

I tried to do this but I get Parse Error:

=QUERY(INDIRECT("Overview!L5")!A2:F;"select C, sum(F) where A='December' group by C order by sum(F) desc")

In which Overview!L5 is the cell with sheet name to query. I also tried to concatenate quotes around INDIRECT but that didnt work either.

I think it is quite evident what I am trying to do from the query i.e. get sum of values in cells grouped by values in other cells.


回答1:


the INDIRECT looks to be the problem. Try like this:

=query(INDIRECT(A1&"!A5:A10"),"select Col1")

i.e. if Cell A1 contains "food" the above is the same as:

=query(food!A5:A10,"select A")

and the same as:

=query(INDIRECT("food!A5:A10"),"select *")

**Note: the indirect uses "Col1" etc and not "A" because it does not pass the col letters.

Also ... The google groups forum might be a good place to look for spreadsheet formula answers. productforums.google.com/forum/#!categories/docs/spreadsheets



来源:https://stackoverflow.com/questions/14850828/dynamic-sheet-name-in-query-in-google-spreashsheet

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