繁体   English   中英

sumifs循环所有工作表

[英]sumifs to loop all sheets

我一直在寻找不同的论坛,似乎无法找到我的答案。 我有相当基本的VBA知识,并在线构建我的大部分代码!

无论细胞参考如何,我都可以在以后解决这些问题。 请你能告诉我如何在多张纸上制作一个sumifs公式参考。 这将被构建到一个模板中,每次运行时都会有不同数量的表单,因此我将无法引用这些表单。

对不起,有点模糊,谢谢先进

谢谢,所以对于其他需要这个的人来说,这就是我原来的公式完全如何完成的

"=SUMPRODUCT(SUMIF(INDIRECT(" '"&Invoices&"'!"&"A2006:A3005"),A3,INDIRECT("'"&Invoices&"'!"&"B2006:B3005")))" 

直接放入单元格时这很有效,但正如您所看到的,当将其添加到VBA时,它会将其作为注释读取。 为了解决这个问题,每次使用“你需要添加额外”时,如下所示(在公式末尾的“=开始时和之后”除外)

 *****'list all the sheet names in cell AI1 of the sheet summary*****
For i = 1 To Sheets.Count
Sheets("Summary").Range("AI1")(i, 1).Value = Sheets(i).Name
Next i
***'clear the first 3 entries in AI as i didnt need the first three sheet names***
Sheets("Summary").Select
Sheets("Summary").Range("AI1:AI3").Clear
***'select the first sheet name, which is in AI4 as we cleard the first 3 to the last used cell, e.g Ctrl.Shift.down*** 
Sheets("Summary").Activate
Sheets("summary").Range(ActiveSheet.Range("AI4"),    ActiveSheet.Range("AI4").End(xlDown)).Select
***' Name the range invoices***
Selection.Name = "Invoices"
' ***Formula to do a sumIf looping all the shets in the named range Invoices***
Sheets("summary").Range("B3").Formula = "=SUMPRODUCT(SUMIF(INDIRECT(""'""&Invoices&""'!$A$2006:$A$3005""),$A3,INDIRECT(""'""&Invoices&""'!B$2006:B$3005"")))"

暂无
暂无

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

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