Sumprod评估提供名称vba

我试图在vba中使用Sumproduct函数。 首先我试过这个:

sht.Cells(LastRowsht + 1, 6) = Application.SUMPRODUCT((Transaction = "Vente") * (TickerD2 = sht.Cells(LastRowsht + 1, 2)), ValeurFlux)) 

在交易中,TickerD2和ValeurFlux是相同长度的范围(这是一整列)。 我曾经在很多论坛上看到,在有标准的情况下,vba中的产品是有问题的。

人们build议使用。评估

  sht.Cells(LastRowsht + 1, 6) = Application.Evaluate("SOMMEPROD((Transaction = "Vente") * (TickerD2 = sht.Cells(LastRowsht + 1, 2)), ValeurFlux)") 

但是它给出了名字。 我使用SOMMEPROD,因为我的Excel是法文的,所以我想我需要翻译。 我认为公式中有一个input错误,但是我不熟悉评估。

谢谢。


这是我在Excel中使用的公式,它的工作原理! 我不知道为什么在vba它不能

  =SOMMEPROD((Data2!D:D="Achat")*(Data2!C:C=B8);Data2!I:I) 

我看到的两个主要问题是在引用string中使用时必须加倍引号,并且需要sht.Cells(LastRowsht + 1, 2)的Range.Address属性 ,而不是Range.Cells属性本身。

  Dim sumproductFormula As String sumproductFormula = "SUMPRODUCT((Transaction=""Vente"")*" & _ "(TickerD2=" & sht.Cells(LastRowsht + 1, 2).Address & ")," & _ "ValeurFlux)" sht.Cells(LastRowsht + 1, 6) = Application.Evaluate(sumproductFormula) 

我发现构build一个分配给stringtypesvar的长段的string比较容易,只需在Application Evaluate中使用var即可。