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&""'!$A06:$A05""),$A3,INDIRECT(""'""&Invoices&""'!B06:B05"")))"