Countif Query

  • Thread starter Thread starter dewald
  • Start date Start date
D

dewald

Hi All.

I got a query today. I really hope you'll be able to help.

I have a list of ages, and i want to count how many people are between the
ages of 29 and 40. I though that the countif function would work but to my
despare i couldn't get it to work. could someone please help me. It would be
much appreciated.

Thanks
Dewald
 
Hello,

Say your data set is in A1 to A6 and is the following:

74
15
30
36
30
2

The formula would be:

=COUNT($A$1:$A$6)-COUNTIF($A$1:$A$6,">40")-COUNTIF($A$1:$A$6,"<29")

What you do is count the total number subtract the number over 40 and
subtract the number under 29. This should give you 3 for the example
dataset.

HTH,
Raj

AnalysisWorks Inc
Evidence-Based Analytic Consulting
www.analysisworks.net

Download a free Excel Box Plot add-in:
http://www.analysisworks.net/downloads.htm#BoxPlotPro
 
Dewald,

You can use two countif's to accomplish your goal

=COUNTIF(A1:A100,">=29")-COUNTIF(A1:A100,">40")

will give a count of all ages 29 <= age <= 40

Dan E
 
This is a very commonly asked question, the standard answers to which
are either a SUMPRODUCT formula or a combination of two COUNTIF
formulas, each of which needs to have the appropriate <, >, <= and >=
symbols, depending on which end values are to be included. The following
is little function that can be used for all four of the possibilities:
Include both endpoints--True,True (or omit both Boolean arguments);
include neither endpoint--False, False; include the lower endpoint but
not the upper--True,False; or omit the lower endpoint but not the
upper--False,True. It is not, of course, as efficient as the
appropriate formula with the appropriate comparison operators for a
particular case, but it might be easier to use than puzzling out the
appropriate comparison operators each time.

Function COUNTBETWEEN(rng, valLow, valHigh, _
Optional inclLow As Boolean = True, _
Optional inclHigh As Boolean = True)
Select Case inclLow & inclHigh
Case "TrueTrue"
COUNTBETWEEN = Application.CountIf(rng, ">=" & valLow) _
- Application.CountIf(rng, ">" & valHigh)
Case "FalseFalse"
COUNTBETWEEN = Application.CountIf(rng, ">" & valLow) _
- Application.CountIf(rng, ">=" & valHigh)
Case "FalseTrue"
COUNTBETWEEN = Application.CountIf(rng, ">" & valLow) _
- Application.CountIf(rng, ">" & valHigh)
Case "TrueFalse"
COUNTBETWEEN = Application.CountIf(rng, ">=" & valLow) _
- Application.CountIf(rng, ">=" & valHigh)
End Select
End Function

Alan Beban
 
Back
Top