简体   繁体   English

从多个工作表中获取相同单元格的值

[英]Get value of same cell from multiple sheets

I'd like to get the value of cell A1 from multiple tabs in my sheet.我想从工作表中的多个选项卡中获取单元格 A1 的值。 I attempted to use INDIRECT , only to be reminded that it wouldn't work in an ARRAYFORMULA .我试图使用INDIRECT ,只是被提醒它在ARRAYFORMULA中不起作用。 Is there some sort of "makeshifty" formula that would do the same thing?是否有某种“临时”公式可以做同样的事情?

This is what I originally attempted:这是我最初尝试的:

 =ArrayFormula(IF(LEN(A2:A),INDIRECT(A2:A&"!A1"),))

Column A is a select list of the tab names in my sheet. A 列是我工作表中选项卡名称的 select 列表。 So the first instance works, but of course, it doesn't populate down the column as I had hoped.所以第一个实例有效,但当然,它并没有像我希望的那样填充到列中。 I realize I can just copy the formula down the column, but some type of an ARRAYFORMULA would be ideal as I add rows to the list.我意识到我可以将公式复制到列中,但是当我向列表中添加行时,某种类型的ARRAYFORMULA将是理想的。

I found this answer , but don't see how I could apply it to my situation.我找到了这个答案,但不知道如何将其应用于我的情况。

I also found this answer , but thought since it's 2.5 years old, maybe someone has discovered a clever way to avoid the drag of copying.我也找到了这个答案,但认为自从它 2.5 岁以来,也许有人发现了一种避免复制拖累的聪明方法。

Answer:回答:

You need to do this with a script or by using the drag method - INDIRECT uses a string reference and so can't be used with an array.您需要使用脚本或使用拖动方法来执行此操作 - INDIRECT使用字符串引用,因此不能与数组一起使用。

More Information:更多信息:

Unfortunately for the user of INDIRECT with ARRAYFORMULA , a discovery of a clever method isn't the issue - the limitation of what can be done with only formulae that is the root of this problem.不幸的是,对于使用ARRAYFORMULAINDIRECT的用户来说,发现一个聪明的方法并不是问题——只能用公式来做的事情是这个问题的根源。

Setting up a custom function:设置自定义 function:

From the Tools > Script editor menu item, you can create scripts.从工具 > 脚本编辑器菜单项,您可以创建脚本。 An example custom formula that you could use would be as follows:您可以使用的示例自定义公式如下:

function ARRAYINDIRECT(input) {  
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  return input.reduce(function(array, el) {
    if (el[0]) array.push(el[0])
    return array;
  }, []).map(x => ss.getSheetByName(x).getRange("A1").getValue());
}

Make sure to then save the script with the save icon.然后确保使用保存图标保存脚本。

In your Sheet you can then call this custom formula as so:在您的工作表中,您可以这样调用此自定义公式:

=ARRAYINDIRECT(A2:A)

Rundown of the function: function 的概要:

  • Takes the input range from where the formula is called - in this case A2:A从调用公式的地方获取输入范围 - 在本例中为A2:A
  • Reduces the input to remove all cells that are empty减少输入以删除所有空单元格
  • Maps the name of the sheet which is stored in the cell to the value in A1 of the sheet it references将存储在单元格中的工作表名称映射到它引用的工作表的A1中的值
  • Returns an array to output返回一个数组到 output

I hope this is helpful to you!我希望这对你有帮助!

References:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 表格中的弹性报表数据-从多张表格中提取(相同的电子表格) - Elastic Report Data in Sheets - Pulling from Multiple Sheets (Same Spreadsheet) Excel - UDF Function 根据条件从多个工作表中获取 SUM 值 - Excel - UDF Function to get the SUM value from multiple sheets based on criteria 从另一张纸上获取价值并将其放入数组中 - Get value from another sheets and put it in array jquery - 从具有相同id的多个下拉列表中获取值 - jquery - get value from multiple dropdowns with same id 对相同范围的多张纸进行排序 - Sorting Multiple Sheets With the Same Range Google 表格:固定单元格值的数组公式 - Google Sheets: Array formula for fixed cell value 在多个工作表数组中匹配值 - Match value in multiple sheets array 如何从多个表单字段中获取数据,然后以相同的表单将它们作为数组提交到单个数据库单元中? - How can I get data from multiple form fields, and then submit them with the same form into a single database cell as a array? 获取具有相同class的多个项目的值 - Get the value of multiple items with the same class 如何使用 Google 表格中查询 function 的 select 语句从单元格中获取文本? - How can I get text from a cell using the select statement of the query function in Google Sheets?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM