Counting a subset

  • Thread starter Thread starter Kent McPherson
  • Start date Start date
K

Kent McPherson

I have data with multiple columns. I want to count all items in column A =
"X" and with column B > 250. I know how to do either condition but I need
to join the two. Any help would be appreciated. Thanks!
 
This could do it.

For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
If Cells(i, 1) = "X" and Cells(i, 1).Offset(0, 1) > 250 Then
'Do things
End If
Next
 
=sumproduct((a1:a1000="X")*(b1:b1000>250))
change range to fit


"Kent McPherson" skrev:
 
Sorry Kent, I forgot to put the counter on it.

Sub cnt()
Counter = 0
For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
If Cells(i, 1) = "X" and Cells(i, 1).Offset(0, 1) > 250 Then
'Do things
Counter = Counter + 1
End If
Next
MsgBox Counter
End Sub
 
Thanks, I've tried this formula but it doesn't give me the right answer.
For example, I should get an answer of 3 but it gives me 10. If I change
either parameter to 1, I get the proper count but when it's together, I get
the wrong answer. Is there any way to debug? Suggestions?
 
Back
Top