简体   繁体   English

从Excel中的多个工作表返回数据

[英]Returning data from across multiple worksheets in Excel

How do you create formulas that will return the totals, averages, counts, min, max, etc from different worksheets? 如何创建公式,以从不同的工作表中返回总数,平均值,计数,最小值,最大值等? The columns (that exist) are consistent in their header information, but may or may not be different from one sheet to the next, column number wise. (存在的)列的标题信息是一致的,但是从一张纸到下一张纸可能会相同,也可能不会不同。 Let's say I have 7 tabs of data, some or all of them may contain a column heading of beans, for example, but the column numbers may or may not be consistent across all tabs, where present. 假设我有7个数据标签,例如,其中的某些或全部可能包含bean的列标题,但是所有标签之间的列号可能一致,也可能不一致。 Their actual locations within the worksheet are completely dynamic. 它们在工作表中的实际位置是完全动态的。

My spreadsheet has several tabs of raw data that I want to compare against in a summary/report sheet. 我的电子表格具有几个要在摘要/报告表中与之进行比较的原始数据选项卡。 I'm sure this can be done but I am afraid it is a little too far beyond the capability of this old brain. 我敢肯定这是可以做到的,但恐怕这超出了这个老脑子的能力。

I've thought about and toyed with a bunch of formulas using indirect, index, match and just can't figure it out. 我已经考虑过,并且使用了一系列使用间接,索引,匹配的公式,但无法弄清楚。 Your help would be most appreciated. 您的帮助将不胜感激。 Thanks 谢谢

Here's a possible function only solution. 这是一个仅适用于功能的解决方案。 The final result will look like: 最终结果将如下所示:

在此处输入图片说明

We will use four(4) primary functions: 我们将使用四(4)个主要功能:

  1. ADDRESS 地址
  2. INDIRECT 间接
  3. MATCH 比赛
  4. LEFT 剩下

Note: Just follow the link if you have question on how to use these functions 注意:如果您对如何使用这些功能有疑问, 点击链接

The formula: This is in cell C4 Above 公式: 在上面的单元格C4中

=AVERAGE(
         INDIRECT(
                  "'"& C$3 & "'!" &                                          
                  LEFT(ADDRESS(1,MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0),4,1),1)
                  & ":" &
                  LEFT(ADDRESS(1,MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0),4,1),1)
                  )
        )

Edit1: To handle the comment below for headers beyond 26, change this Edit1:要处理以下针对超过26的标题的评论,请更改此

LEFT(ADDRESS(1,MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0),4,1),1)

to this: 对此:

SUBSTITUTE(ADDRESS(1,MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0),4,1),"1","")

Basically what is does is: 基本上做什么是:

  • Find where the header Bean is located using MATCH function. 使用MATCH函数查找标头Bean所在的位置。 To do that, you will have to incorporate the use of INDIRECT since your sheet name is dynamic (in this example, your sheet name is in C3 - Data1 ). 为此,由于工作表名称是动态的,因此必须合并使用INDIRECT (在此示例中,工作表名称在C3- Data1 )。 (I assumed all your headers are in 1st row, I use 1:1 in there) . (我假设您的所有标头都在第一行,我在其中使用1:1 Note: In this example, Bean is in column H of Data1 sheet 注意:在此示例中, Bean位于Data1表的H列中

     MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0) <~~ returns 8 
  • After finding where it is, we need to get the entire column address so we can apply counting and summing functions (eg SUM,COUNT,AVERAGE etc...). 找到它的位置后,我们需要获取整个列地址,以便我们可以应用计数和求和功能(例如SUM,COUNT,AVERAGE等)。 To do that we use the ADDRESS function combined with LEFT to get the column letter. 为此,我们将ADDRESS函数与LEFT结合使用以获得列字母。

     LEFT(ADDRESS(1,MATCH($E$2,INDIRECT("'"&C$3&"'!1:1"),0),4,1),1) <~~ returns H 
  • Then we just repeat that formula and connect it with : to get H:H 然后,我们只需重复该公式并将其与:连接即可得到H:H

  • Now that we have the column address, we simply connect it again with the sheet name and apply the final INDIRECT function plus the counting and/or summing function of your choice. 现在我们有了列地址,我们只需再次将其与工作表名称连接起来,然后应用最终的INDIRECT函数以及您选择的计数和/或求和函数。

Sample formula of Total in C5 : C5总计示例公式:

在此处输入图片说明

Sample formula of Max in C6 : C6Max的示例公式:

在此处输入图片说明

Finally, all you have to do is copy the formula across all columns with sheet name. 最后,您所要做的就是在带有工作表名称的所有列中复制公式。
Just add sheet names beside the last one and copy formula. 只需在最后一个名称旁边添加工作表名称并复制公式即可。 That's it. 而已。 I hope this is close to what you want and I hope that all the functions I used are available in Excel 2000. 我希望这接近您想要的,并且希望我使用的所有功能在Excel 2000中都可用。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM