I want to do a sumif from an array but i am not sure how to reference a full column in an array. For instance i have the following data in excel (in columns A and B) and code that works fine,
RR TT
1 J
2 K
3 J
4 K
5 J
5 K
6 J
7 K
8 J
9 K
Sub test()
Dim s As Range
Dim s2 As Range
Set s = Range("A2:A11")
Set s2 = Range("B2:B11")
e = WorksheetFunction.SumIfs(s, s2, "J")
MsgBox e
End Sub
This sums the RR column where the TT column equals "J" and the answer is 23. But in the code i assign each column to a seperate Range in VBA. I would like to assign both columns to an array and do the sumifs from the array. The first part of the code would then look as follows,
Dim s() As Variant
ReDim s(1 To 10, 1 To 2)
s = Range("A2:B11")
How do i then reference the columns of the array in the sumifs function? (the first two entries in the sumifs function)
e = WorksheetFunction.SumIfs(?, ?, "J")
I will at the end work with a much bigger dataset and if it is possible i would like not create a ton of seperate Ranges but just one array.