Google Sheets QUERY 从选项卡名称列表中提取,这将在添加新选项卡时提取新选项卡数据
我有一个 Google Apps 脚本,将 Google 表格中每个选项卡的名称拉入一个列表。这些选项卡按月份和年份标记(即 2020 年 2 月),但自 2 月以来我没有每个月的选项卡。当我有新数据(并不总是每个连续月份)时,我会创建一个新选项卡几个月。
通过这些选项卡,我想查询所有选项卡中每个选项卡上 D 列中的所有唯一值。我想知道是否可以在预期潜在的新选项卡时执行此操作,这样我就不必在添加新选项卡时去更新查询?
目前,我有现有选项卡的列表,并连接到单元格 C2:C6 中的范围(因此每个选项卡/范围都列为 2020 年 1 月!A:D)。我正确提取唯一值的查询是:
=UNIQUE(QUERY({INDIRECT(C2);INDIRECT(C3);INDIRECT(C4);INDIRECT(C5);INDIRECT(C6)},"Select Col4 where Col4 is not null",1))
是否有一种方法可以将新的月份/日期添加到现有选项卡列表中,以预期将来可能添加该选项卡名称,并添加那些尚未存在的选项卡将选项卡名称添加到查询中,但如果在工作表中找不到该选项卡,则告诉它忽略它?
先感谢您!
I have a Google Apps Script pulling the names of each tab in my Google Sheet into one list. The tabs are labeled by month and year (i.e., February 2020) but I don't have a tab for every single month since February. I create a new tab for months when I have new data which is not always every consecutive month.
With these tabs, I want to query all unique values across all tabs, in column D on each of the tabs. I'm wondering if it's possible to do this in anticipation for potential new tabs, so I don't have to go and update the query whenever I add a new tab?
Currently I have the list of existing tabs and concatenated to include the range (so each tab/range is listed as January 2020!A:D, for example) in cells C2:C6. The query I have that is correctly pulling unique values is:
=UNIQUE(QUERY({INDIRECT(C2);INDIRECT(C3);INDIRECT(C4);INDIRECT(C5);INDIRECT(C6)},"Select Col4 where Col4 is not null",1))
Is there a way to possibly add new month/dates to the list of existing tabs in anticipation of that tab name possibly being added in the future, and adding those not-yet-existing tab names into the query, but telling it to ignore it if it can't find that tab in the sheet?
Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几种方法可以解决这个问题:
可以像这样忽略不存在的工作表:
注意 A:D = 中的 4 列4 个空槽
{"","","",""}
请参阅:
https://stackoverflow.com/a/69067831/5632629
https://stackoverflow.com/a/57452968/5632629
https://stackoverflow.com/a/58599649/5632629
https://stackoverflow.com/a/68447014/5632629
https://stackoverflow.com/a/61819704/5632629
there are several ways how to solve this:
non-existing sheets can be ignored like this:
note 4 columns in A:D = 4 empty slots
{"","","",""}
see:
https://stackoverflow.com/a/69067831/5632629
https://stackoverflow.com/a/57452968/5632629
https://stackoverflow.com/a/58599649/5632629
https://stackoverflow.com/a/68447014/5632629
https://stackoverflow.com/a/61819704/5632629