Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default CountIf for two columns

I have two columns populated with different values.
I would like to count all the cells pair having specific values, i.e. like
countif function, but for both cells.
For now I am doing this concatenating both columns and after that performing
CountIf over resulting column.
Another way is to write a piece of code looping and counting, but it seems
too much for such a simple thing.
Is there any other way of doing that? Without intermediate steps, only using
one formula?

Thanks,
Yakimo


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default CountIf for two columns

One way:

Assume your columns are A & B. Further assume your criteria are in
D1 (for column A) and E1 (for column B):

=SUMPRODUCT(--(A1:A1000=D1),--(B1:B1000=E1))


In article ,
"Yakimoto" wrote:

I have two columns populated with different values.
I would like to count all the cells pair having specific values, i.e. like
countif function, but for both cells.
For now I am doing this concatenating both columns and after that performing
CountIf over resulting column.
Another way is to write a piece of code looping and counting, but it seems
too much for such a simple thing.
Is there any other way of doing that? Without intermediate steps, only using
one formula?

Thanks,
Yakimo


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default CountIf for two columns

Thanks J.E., this is exactly what I needed.
Could you tell me what are these two minuses for in the formula
(--(A1:A1000=D1) ?

"J.E. McGimpsey" wrote in message
...
One way:

Assume your columns are A & B. Further assume your criteria are in
D1 (for column A) and E1 (for column B):

=SUMPRODUCT(--(A1:A1000=D1),--(B1:B1000=E1))


In article ,
"Yakimoto" wrote:

I have two columns populated with different values.
I would like to count all the cells pair having specific values, i.e.

like
countif function, but for both cells.
For now I am doing this concatenating both columns and after that

performing
CountIf over resulting column.
Another way is to write a piece of code looping and counting, but it

seems
too much for such a simple thing.
Is there any other way of doing that? Without intermediate steps, only

using
one formula?

Thanks,
Yakimo




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default CountIf for two columns

SUMPRODUCT returns an array of True/False values. The -- is to coerce these
into 0/1 values that can be added up.

Could I suggest that you look at this previous NG posting where Ken Wright
gives a pretty thorough explanation

http://tinyurl.com/v85r

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Yakimoto" wrote in message
...
Thanks J.E., this is exactly what I needed.
Could you tell me what are these two minuses for in the formula
(--(A1:A1000=D1) ?

"J.E. McGimpsey" wrote in message
...
One way:

Assume your columns are A & B. Further assume your criteria are in
D1 (for column A) and E1 (for column B):

=SUMPRODUCT(--(A1:A1000=D1),--(B1:B1000=E1))


In article ,
"Yakimoto" wrote:

I have two columns populated with different values.
I would like to count all the cells pair having specific values, i.e.

like
countif function, but for both cells.
For now I am doing this concatenating both columns and after that

performing
CountIf over resulting column.
Another way is to write a piece of code looping and counting, but it

seems
too much for such a simple thing.
Is there any other way of doing that? Without intermediate steps, only

using
one formula?

Thanks,
Yakimo






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default CountIf for two columns

SUMPRODUCT expects numeric values. (A1:A1000=D1) returns an array of
boolean (TRUE/FALSE) values, which would be ignored. Boolean values
are coerced by XL to 1 (TRUE) and 0 (FALSE) in math formulas, so
putting a "unary minus operator" (negative sign) in front of the
quantity converts the array to numbers (i.e, -1 for TRUE and 0 for
FALSE). The second unary minus converts the -1s to positive values.

These arrays are then multiplies and summed by SUMPRODUCT().


In article ,
"Yakimoto" wrote:

Thanks J.E., this is exactly what I needed.
Could you tell me what are these two minuses for in the formula
(--(A1:A1000=D1) ?

"J.E. McGimpsey" wrote in message
...
One way:

Assume your columns are A & B. Further assume your criteria are in
D1 (for column A) and E1 (for column B):

=SUMPRODUCT(--(A1:A1000=D1),--(B1:B1000=E1))


In article ,
"Yakimoto" wrote:

I have two columns populated with different values.
I would like to count all the cells pair having specific values, i.e.

like
countif function, but for both cells.
For now I am doing this concatenating both columns and after that

performing
CountIf over resulting column.
Another way is to write a piece of code looping and counting, but it

seems
too much for such a simple thing.
Is there any other way of doing that? Without intermediate steps, only

using
one formula?

Thanks,
Yakimo




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
COUNTIF with 2 columns J.A.1975 Excel Worksheet Functions 2 April 28th 11 03:36 PM
COUNTIF for 2 columns b1llt Excel Worksheet Functions 7 March 29th 10 06:52 PM
COUNTIF - across 2 columns Rebekah Excel Worksheet Functions 11 November 9th 09 03:43 PM
Countif for 2 columns earlfj Excel Worksheet Functions 3 September 27th 09 05:42 AM
countif in 2 columns Tonso Excel Discussion (Misc queries) 4 October 23rd 07 04:51 PM


All times are GMT +1. The time now is 11:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"