I want to have a simple sumif in my macro that will loop through a range. In my code below I don't know what to put where
I have XXX to make this work:
Everything is in same worksheet. The function without VBA would be very simple =SUMIF(D7:D707,O9,I7:I707)
Any advice appreciated.
I have XXX to make this work:
Everything is in same worksheet. The function without VBA would be very simple =SUMIF(D7:D707,O9,I7:I707)
Code:
Dim wsJournal As Worksheet
Dim LR As Long
Dim CritRng As Range, SumRng As Range
With wsJournal
Set CritRng = Range("D7:D" & Cells(Rows.Count, D).End(xlUp).Row)
Set SumRng = Range("I7:I" & Cells(Rows.Count, I).End(xlUp).Row)
LR = .Range("O9:O" & Cells(Rows.Count, "O").End(xlUp).Row)
n = 9
For n = 9 To LR
Cells(r, LR) = WorksheetFunction.SumIf(CritRng, XXXX, SumRng)
End With
End Sub