简体   繁体   English

在Excel中(从vb.net运行),我可以将一张工作表中所有单元格的值添加到另一张工作表中的单元格中吗?

[英]in excel, running from vb.net, can I add the values of all the cells in one sheet to the cells in a different sheet?

I have a vb.net application that uses excel. 我有一个使用Excel的vb.net应用程序。 One of the things it does is total the cells in a certain by a certain type, which for the purposes of this question is not relevant. 它要做的一件事是将某个单元格中的某个单元格总数归为某种类型,对于该问题而言,这是无关紧要的。 The result is that the cells in sheeta are added to sheetb. 结果是将sheeta中的单元格添加到sheetb。 This is a repetitive process as multiple copies of sheeta are processed and i want the total of 'all' of the sheeta cells to be added into sheetb. 这是一个重复的过程,因为处理了sheeta的多个副本,我希望将全部“ sheeta”单元的总数添加到sheetb中。 If there were 50 copies of sheeta, then the value of cell A3 in sheetb, for example, would be the total of the values in cell A3 of the sheetA. 如果有50张sheeta,则例如sheetb中单元格A3的值将是sheetA单元格A3中值的总和。 I am doing it as a cludge now by adding the value of each cell individually. 我现在通过单独添加每个单元格的值来做为判断。 I'd like to be able to use all of the cells in a few statements only, without doing addition statements repetitively. 我只想只在几个语句中使用所有单元格,而不必重复执行附加语句。 Thanks for the help 谢谢您的帮助

You have a couple of options: 您有两种选择:

  1. You can write code to cycle through the sheets to build a SUM formula in sheetb for each of the instances of sheeta 可以通过片材编写代码来循环构建SUM在式sheetb针对每个实例的sheeta

  2. You can consider using a PivotTable that draws from multiple sources. 您可以考虑使用从多个来源绘制的PivotTable表。 Then you simply need to refresh the PivotTable whenever data changes in any of the source sheets. 然后,只要任何源工作表中的数据发生更改,您只需刷新数据透视表。 You can refer to this Microsoft Support Page for instruction on how to build it: https://support.office.com/en-ca/article/Consolidate-multiple-worksheets-into-one-PivotTable-report-3ae257d2-ca94-49ff-a481-e9fc8adeeeb5 您可以参考此Microsoft支持页面以获取有关如何构建它的说明: https : //support.office.com/en-ca/article/Consolidate-multiple-worksheets-into-one-PivotTable-report-3ae257d2-ca94- 49ff-a481-e9fc8adeeeb5

In either case, you will need to be weary that if you add additional instances of sheeta (or remove them), then you will need to rebuild the formula in option 1 or the PivotTable in option 2. 在这两种情况下,您都将感到疲倦,如果您添加了sheeta其他实例(或删除了它们),那么您将需要在选项1中重新sheeta公式或在选项2中重新sheeta数据透视表。

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

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