SUMIFS in VBA

Lectricman

New Member
Joined
Feb 18, 2016
Messages
14
Can anyone explainto me what is wrong with this Formula.
=SUMIFS(F760:F841,B760:B841,"A",I760:I841,"B",J760:J841,"C",K760:K841,"D")
On a worksheet it works without issue. When I try it in VBA it gives the following error.

Compile Error:
Expected: List Separator or)
.

The colon between F760 and F841 is hi-lighted.


Many Thanks in advance
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Select the cell with formula, then in the Vb editor put this in the Immediate window (Ctrl G will bring it up if needed)
Code:
?Replace$(activecell.formular1c1, """", """""")
Then copy & paste the result into your macro

Picked this up from RoryA
 
Last edited:
Upvote 0
Can you post a snippet of the code to show exactly how you used this formula in VBA?
 
Upvote 0
A couple ways to call SUMIFS from VBA:

Code:
    x = Evaluate("SUMIFS(F760:F841,B760:B841,""A"",I760:I841,""B"",J760:J841,""C"",K760:K841,""D"")")
    
    y = WorksheetFunction.SumIfs(Range("F760:F841"), Range("B760:B841"), "A", Range("I760:I841"), "B", Range("J760:J841"), "C", Range("K760:K841"), "D")

Note the double quotes in the interior of the first line. Fluff's Replace trick will do that for you.
 
Upvote 0
A couple ways to call SUMIFS from VBA:

Code:
    x = Evaluate("SUMIFS(F760:F841,B760:B841,""A"",I760:I841,""B"",J760:J841,""C"",K760:K841,""D"")")
    
    y = WorksheetFunction.SumIfs(Range("F760:F841"), Range("B760:B841"), "A", Range("I760:I841"), "B", Range("J760:J841"), "C", Range("K760:K841"), "D")

Note the double quotes in the interior of the first line. Fluff's Replace trick will do that for you.

Thank you so much. The top one did it for me.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top