SUMPRODUCT Formula in VBA

前端 未结 3 825
粉色の甜心
粉色の甜心 2021-01-14 10:07

I want to use following SUMPRODUCT formula in VBA:

=SUMPRODUCT((Sale!$J$5:$J$1048576=C12)*Sale!$D$5:$D$1048576,Sale!$M$5:$M$1048576)
         


        
3条回答
  •  执笔经年
    2021-01-14 10:37

    Two possible simple solutions, given that worksheetfunction methods won't work with arrays the size that you are using:

    First, add the formula and then replace it with its value

    With activesheet.Range("F12")
       .Formula =" =SUMPRODUCT((Sale!$J$5:$J$1048576=C12)*Sale!$D$5:$D$1048576,Sale!$M$5:$M$1048576)"
       .Value2 = .Value2
    End With
    

    Second, use Evaluate:

    With Activesheet
       .range("F12").Value2 = .Evaluate("SUMPRODUCT((Sale!$J$5:$J$1048576=C12)*Sale!$D$5:$D$1048576,Sale!$M$5:$M$1048576)")
    End With
    

提交回复
热议问题