Application.WorksheetFunction.SumIf: a range as a criteria

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
Office Version
  1. 2007
Hello everybody.

I'm struggling with a variant of sumif.

Below a classic example:

Code:
Result = Application.WorksheetFunction.SumIf(Range("A:A"), Range("C1").Value, Range("B:B"))

Now, suppose the criteria is not univocal.

I mean: the criteria is not in C1, but has to correspond in one of the value included in a range.

For example, in the range rng

Code:
dim lr as long
lr = Cells(Rows.Count, "C").End(xlUp).Row
set rng as range
rng = Range("C2:C" & lr)

How can I figure this out?

Thank's in advance.
 
Last edited:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hello everybody.

I'm struggling with a variant of sumif.

Below a classic example:

Code:
Result = Application.WorksheetFunction.SumIf(Range("A:A"), Range("C1").Value, Range("B:B"))

Now, suppose the criteria is not univocal.

I mean: the criteria is not in C1, but has to correspond in one of the value included in a range.

For example, in the range rng

Code:
dim lr as long
lr = Cells(Rows.Count, "C").End(xlUp).Row
set rng as range
rng = Range("C2:C" & lr)

How can I figure this out?

Thank's in advance.

This way is impossible:

Code:
Result = Application.WorksheetFunction.SumIf(Range("A:A"), Range("C2").Value, Range("B:B")) +  _
 Application.WorksheetFunction.SumIf(Range("A:A"), Range("C3").Value, Range("B:B")) [COLOR="#FF0000"][B]+ ... + _
 [/B][/COLOR] Application.WorksheetFunction.SumIf(Range("A:A"), Range("C[COLOR="#FF0000"][B]?[/B][/COLOR]").Value, Range("B:B"))
 
Last edited:
Upvote 0
You could loop.
Code:
Dim i as Long, lr as Long, mySum as Long

lr = Cells(Rows.Count, "C").End(xlUp).Row

For i = 1 to lr
    mySum = mySum = Application.WorksheetFunction.SumIf(Range("A:A"), Cells(i, 3).Value, Range("B:B"))
Next i
 
Upvote 0
You could loop.
Code:
Dim i as Long, lr as Long, mySum as Long

lr = Cells(Rows.Count, "C").End(xlUp).Row

For i = 1 to lr
    mySum = mySum = Application.WorksheetFunction.SumIf(Range("A:A"), Cells(i, 3).Value, Range("B:B"))
Next i

It works fine. Thank you.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,052
Messages
6,122,878
Members
449,097
Latest member
dbomb1414

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