1

I have a problem with using the SUMIFS in VBA. The thing is I need to use SUMIFS to sum 1+ cities in my dataset.

I have tried to google and use STackoverflow and found 2 anwers where I tried both, but none of them workd. One of them was:

VBA - SumIfs with Or

Dim D As Double

D = WorksheetFunction.Sum(WorksheetFunction.SumIfs(Range("D2:D2000"), _
Range("A2:A2000"), Array("Århus", "København")))
MsgBox D

I expect a numeriacal result, but I get the result "Run-time error '13': Type mismatch"

0

1 Answer 1

2

These will need to be late bound so use Application. instead of WorksheetFormula:

As per @MathieuGuindon:

The result should be captured into a Variant to prevent a type mismatch upon assignment of D if any of the values involved is a worksheet error.

Dim D As Variant

D = Application.Sum(Application.SumIfs(Range("D2:D2000"), _
Range("A2:A2000"), Array("Århus", "København")))
If IsNumeric(D) Then MsgBox D
Sign up to request clarification or add additional context in comments.

2 Comments

The result should be captured into a Variant to prevent a type mismatch upon assignment of D if any of the values involved is a worksheet error.
@MathieuGuindon added.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.