VBA中的Sumif公式

时间:2018-03-23 12:48:03

标签: excel vba excel-vba

我有一个宏添加两个新的首页ws2和ws3

以下vlookup公式正常

With ws3.Range("E4:E" & LastRow)
    .Formula = "=VLOOKUP(A4," & ws2.Name & "!A:C,3,FALSE)" 
End With

但是当我想在列F中添加另一个公式时,即excel公式SUMIF(January!G:G,A:A,January!H:H),当我按以下方式重写时,它不起作用

With ws3.Range("F4:F" & LastRow)
   .Formula = "=SUMIF(" & ws2.Name & " ! G:G, A:A ," & ws2.Name & " !H:H)"
End With

我在Excel论坛上提出了同样的问题,但尚未收到回复。

https://www.mrexcel.com/forum/excel-questions/1048876-vba-adding-formulas-referencing-new-sheet.html

1 个答案:

答案 0 :(得分:1)

sumif期望第二个参数中的单个标准不是范围。

我希望你的参考更像是:

With ws3.Range("F4:F" & LastRow)
   .Formula = "=SUMIF('" & ws2.Name & "'! G:G, A4,'" & ws2.Name & "'!H:H)"
End With
相关问题