vba looping through rows and columns using application worksheetfunction

Gtabtr1

New Member
Joined
Feb 15, 2017
Messages
39
hi all,

I'm trying to loop through several rows and columns using application.worksheetfunction.sumifs. Here is the segment I'm having trouble with:

Dim lcol As Long
Dim rrow as Long
Dim SumRange As Range
Dim Criteria1 As Range
Dim Criteria2 As Range
lcol = Cells(1, Columns.count).End(xlToLeft).Column
rrow = range("A" & rows.count).End(xlUp).Row
Set SumRange = Worksheets(Gs).Range("F2:F" & grow)
Set Criteria1 = Worksheets(Gs).Range("A2:A" & grow)
Set Criteria2 = Worksheets(Gs).Range("C2:C" & grow)

Range("B2").Select
For c = 2 To lcol
For i = 2 To rrow
Worksheets(Rs).Range(i, c) = Application.WorksheetFunction.SumIfs(SumRange, Criteria1, Range("A" & i), Criteria2, Range(c, i))
Next
Next

I'm getting the error message "Method 'Range' of object'_Global' failed" on the last part in red above.
Also if there is a better way than looping I'm all ears. I don't like looping, it takes too long. PLEASE HELP.
Thank you
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Change Range(c, i) to Cells(i, c).
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,361
Members
449,080
Latest member
Armadillos

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