简体   繁体   English

Excel SUMIFS 公式参考其他工作簿

[英]Excel SUMIFS formula with reference to other workbook

Im trying to write a VBA code for which will fill my excel SUMIFS formulas.我正在尝试编写 VBA 代码,该代码将填充我的 excel SUMIFS 公式。 In general SUMIFS will calculate sums based on other workbook data.一般来说,SUMIFS 将根据其他工作簿数据计算总和。 Other workbook filename is currently hardcoded in my macro, however i'd like to make it more flexible and instead of hard coding it i'd like to use a cell in which i put the file name.其他工作簿文件名目前在我的宏中被硬编码,但是我想让它更灵活,而不是硬编码,我想使用一个单元格来放置文件名。

so far macro creates the following formula and puts it in cell:到目前为止宏创建以下公式并将其放入单元格中:

=SUMIFS([SW.xlsx]TeamAllocations!F$9:F$401,[SW.xlsx]TeamAllocations!$D$9:$D$401,$D16,[SW.xlsx]TeamAllocations!$B$9:$B$401,$B16)

what i'd like to have is kind of:我想要的是:

=SUMIFS([<variable evaluated based on a cell which has filename/filepath, eg B1>]TeamAllocations!F$9:F$401,[<variable evaluated based on a cell which has filename/filepath, eg B1]TeamAllocations!$D$9:$D$401,$D16,[<variable evaluated based on a cell which has filename/filepath, eg B1]TeamAllocations!$B$9:$B$401,$B16)

So in B1 cell i'd have "SW_01.xlsx" or "SW_02.xlsx", so the SUMIFS formula will always have up-to-date soruce.所以在 B1 单元格中我会有“SW_01.xlsx”或“SW_02.xlsx”,所以 SUMIFS 公式总是有最新的来源。 Is that possible in excel? excel 有可能吗?

Thanks J.谢谢J。

If all your files have a fixed format, I think you can combine all of the files with power query.如果您所有的文件都有固定格式,我认为您可以将所有文件与电源查询结合起来。 You can do what you want more easily.你可以更轻松地做你想做的事。

Combine Files:合并文件:

https://chandoo.org/wp/combine-excel-files-using-power-query/ https://chandoo.org/wp/combine-excel-files-using-power-query/

Group in PowerQuery (same as SUMIF): PowerQuery 中的组(与 SUMIF 相同):

https://support.office.com/en-us/article/group-rows-in-a-table-power-query-e1b9e916-6fcc-40bf-a6e8-ef928240adf1 https://support.office.com/en-us/article/group-rows-in-a-table-power-query-e1b9e916-6fcc-40bf-a6e8-ef928240adf1

Useful filter:有用的过滤器:

https://exceleratorbi.com.au/pass-excel-parameter-power-query/ https://exceleratorbi.com.au/pass-excel-parameter-power-query/

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

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