简体   繁体   中英

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. 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. 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. 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. 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

  2. You can consider using a PivotTable that draws from multiple sources. 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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