EXCEL VBA formula error with sheet reference

2019-08-28 16:21发布

Could someone please identify where the error is?

Sub calc_external_sales()
    Sheets("Monetary All").[C5].Formula = "=SUMMEWENNS(Rawdata!K2:K3446;Rawdata!I2:I3446;""bezahlt"")"
End Sub

I guess it has to do with the sheets and the range.

2条回答
冷血范
2楼-- · 2019-08-28 16:38

perhaps

Sub calc_external_sales()
    Sheets("Monetary All").[C5].Formula = "=SUMIF(Rawdata!K2:K3446,Rawdata!I2:I3446,""bezahlt"")"
End Sub

or

Sub calc_external_sales()
    Sheets("Monetary All").[C5].FormulaLocal = "=SUMMEWENNS(Rawdata!K2:K3446;Rawdata!I2:I3446;""bezahlt"")"
End Sub
查看更多
倾城 Initia
3楼-- · 2019-08-28 16:45

The problem is that when you are using the quotes around your search criteria ("bezahlt"), it is effectively treating it as two strings that are adjacent to each other with no concatenation. Use this instead:

Sub calc_external_sales()
    Sheets("Monetary All").[C5].Formula = "=SUMMEWENNS(Rawdata!K2:K3446,Rawdata!I2:I3446," & Chr(34) & "bezahlt" & Chr(34) & ")"
End Sub

The chr(34) is the symbol for quotation marks.

查看更多
登录 后发表回答