Dale Fye
asked on
Count # of rows in a range that meet two criteria using VBA
I need to count the number of rows in the range:
shtGroups.Range("A1:B50")
where the value in column A = lngGroup and the value in column B = lngSub
I figured out how to do this in a cell formula, but I need to do it in vba.
shtGroups.Range("A1:B50")
where the value in column A = lngGroup and the value in column B = lngSub
I figured out how to do this in a cell formula, but I need to do it in vba.
OK, try this formula:
Range("A1:A" & Cells(65536, "A").End(xlUp).Row & ",B1:B" & Cells(65536, "A").End(xlUp).Row).Select
Range("A1:A" & Cells(65536, "A").End(xlUp).Row & ",B1:B" & Cells(65536, "A").End(xlUp).Row).Select
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
imnorie,
It worked as soon as I set the focus to shtGroup via Activate and removed the extra quotes for a numeric value.
What is the point of the double negatives "--" at the beginning of each range?
It worked as soon as I set the focus to shtGroup via Activate and removed the extra quotes for a numeric value.
What is the point of the double negatives "--" at the beginning of each range?
If lngGroup and lngSub are numeric
result = Evaluate("SUMPRODUCT(--(A1
If they are strings:
result = strformula = "SUMPRODUCT(--(A1:A50=""" & lngGroup & """), --(B1:B50=""" & lngSub & """))"