下面列出cell AI1中工作表摘要中的所有工作表名称,然后删除顶部3,从AI4到底部选择,并命名范围“发票”
我试着用这个来对所有的床单做一个求和公式。它可以手动将其粘贴到单元格中,但在VBA中时,可以从'"&Invoices&"'!$A$2006:$A$3005"),$A3,INDIRECT("'"&Invoices&"'!B$2006:B$3005")))"中粘贴到单元格中。
从那以后,它就把它当作评论(绿色)阅读。
For i = 1 To Sheets.Count
Sheets("Summary").Range("AI1")(i, 1).Value = Sheets(i).Name
Next i
Sheets("Summary").Select
Sheets("Summary").Range("AI1:AI3").Clear
Sheets("Summary").Activate
Sheets("summary").Range(ActiveSheet.Range("AI4"),
ActiveSheet.Range("AI4").End(xlDown)).Select
Selection.Name = "Invoices"
Sheets("summary").Range("B3").Formula = "=SUMPRODUCT(SUMIF(INDIRECT("'"&Invoices&"'!$A$2006:$A$3005"),$A3,INDIRECT("'"&Invoices&"'!B$2006:B$3005")))"发布于 2016-05-20 13:57:13
为了扩展我的注释: VBA认为“是字符串的结尾,所以如果您希望它实际上被视为一个字符,那么您需要将它转义为"”。
Sheets("summary").Range("B3").Formula = "=SUMPRODUCT(SUMIF(INDIRECT(""'""&Invoices&""'!$A$2006:$A$3005""),$A3,INDIRECT(""'""&Invoices&""'!B$2006:B$3005"")))"当有很多字符时,检查它的简单方法是将它写在即时窗口中。我把
? "=SUMPRODUCT(SUMIF(INDIRECT(""'""&Invoices&""'!$A$2006:$A$3005""),$A3,INDIRECT(""'""&Invoices&""'!B$2006:B$3005"")))"来确认一下。
发布于 2016-05-20 14:10:45
谢谢,所以对于其他需要这个的人来说,这就是全部的方法。
*****'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"")))"https://stackoverflow.com/questions/37346326
复制相似问题