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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
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,214,926
Messages
6,122,305
Members
449,079
Latest member
juggernaut24

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