MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Nov 20th, 2002, 07:13 AM   #1
Juan Pablo González
MrExcel MVP
 
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,738
Default

Ok, are you ready for this ? you CAN use COUNTIF with multiple ranges, non contigous, etc.

For example, I have this three ranges:

A2:D2
{1,2,3,2}

given the name Rng1

B4:G5
{5,6,7,8,9,10;2,3,4,5,6,7}

name: Rng2

A7:A9
{2;4;6}

name: Rng3

Now, say I want to count the number of 2s in the three ranges. I can use this simple formula:

=SUM(COUNTIF(INDIRECT({"Rng1","Rng2","Rng3"}),2))

it's not even array entered !

Here's the Excel model (Yellow range = Rng1, Green = Rng2, Blue = Rng3)

you can also use this approach for non named ranges, i.e.:

=SUM(COUNTIF(INDIRECT({"A2:D2","B4:G5","A7:A9"}),2))

******** ******************** ************************************************************************>
Microsoft Excel - Book1___Running: xl2002 XP : OS = Windows ME
(F)ile (E)dit (V)iew (I)nsert (O)ptions (T)ools (D)ata (W)indow (H)elp (A)bout
=

A
B
C
D
E
F
G
1
*******
2
1232***
3
*******
4
*5678910
5
*234567
6
*******
7
2******
8
4******
9
6******
10
****Answer44
Sheet1*

[HtmlMaker 2.20] To see the formula in the cells just click on the cells hyperlink or click the Name box
PLEASE DO NOT QUOTE THIS TABLE IMAGE ON SAME PAGE! OTHEWISE, ERROR OF JavaScript OCCUR.

__________________
Regards,

Juan Pablo González
http://www.juanpg.com
Juan Pablo González is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


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


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 by MrExcel Consulting.