简体   繁体   中英

EXCEL VBA formula error with sheet reference

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM