View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Counting Criteria Values with For Loop

Hi,

Am Mon, 5 Jan 2015 02:35:21 -0800 (PST) schrieb :

I'm stuck trying to figure out the right method for this:

In A1:A10 I have:
Smith
Smith
Smith
Jones
Jones
Jones
Jones
Taylor
Taylor
Taylor

In B1:B10 I have:
A
B
A
B
B
A
C
A
A
C

I'm attempting to count the number of A's, B's, and C's for each last name (Smith, Jones, Taylor) to make sure there are 2 of each letter for each last name. If there are more or less than 2 it displays that in Col C for each last name. Is a For loop and Nested Ifs the right way to go about this?


what Excel version do you use?
xl2007 or later you can use COUNTIFS:
=COUNTIFS(A1:A10,"Smith",B1:B10,"A")
(for Smith and A)
In earlier version try:
=SUMPRODUCT(--(A1:A10="Smith"),--(B1:B10="A"))

You could also try a Pivot table. Insert a row for headers. Insert =
Pivot table and drag the names to the row field, the criteria to column
field and values.


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional