sumifs循环所有表

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

不pipe细胞参考如何,我将能够在以后的工作。 请你可以让我如何在多张纸上制作一个sumifs公式参考。 这正在构build到一个模板中,每次运行时会有不同数量的不同名称的表单,所以我将无法引用表单。

对不起,这在先进的模糊感谢

谢谢,对于任何需要这个的人来说,这是完全按照我原来的方式完成的

 "=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, eg 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"")))"