View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Alan Beban[_2_] Alan Beban[_2_] is offline
external usenet poster
 
Posts: 783
Default formula to find how many cell have a number between 2 numbers.

SCOTTAFRED wrote:
I have a column that counts the number of days a person in assigned to my
unit. I am trying to make a formula to count how many people have been in my
unit for 1-30 days, 31-60 days and 61-90 days.


Three versions of a function to do this were recently posted in this
forum; watch for wordwrap:

Public Function CountBetw( _
iRange As Range, _
lowNum As Double, _
hiNum As Double, _
Optional inclLow = True, _
Optional inclHi = True) As Variant
With Application
CountBetw = .CountIf(iRange, "" & String(-inclLow, "=") & lowNum) - _
.CountIf(iRange, "" & String(-Not (inclHi), "=") & hiNum)
End With
End Function

Rick Rothstein

Public Function CountBetw( _
iRange As Range, _
lowNum As Double, _
hiNum As Double, _
Optional inclLow = True, _
Optional inclHi = True) As Variant
Dim sOpLow As String
Dim sOpHi As String
sOpLow = IIf(inclLow, "=", "")
sOpHi = IIf(inclHi, "", "=")
With Application
CountBetw = .CountIf(iRange, sOpLow & lowNum) - _
.CountIf(iRange, sOpHi & hiNum)
End With
End Function

JE McGimpsey

Function CountBetw(iRange As range, lowNum, hiNum, Optional inclLow =
True, Optional inclHi = True)
If inclLow = True And inclHi = True Then
CountBetw = Application.CountIf(iRange, "=" & lowNum) -
Application.CountIf(iRange, "" & hiNum)
ElseIf inclLow = False And inclHi = False Then
CountBetw = Application.CountIf(iRange, "" & lowNum) -
Application.CountIf(iRange, "=" & hiNum)
ElseIf inclLow = True And inclHi = False Then
CountBetw = Application.CountIf(iRange, "=" & lowNum) -
Application.CountIf(iRange, "=" & hiNum)
ElseIf inclLow = False And inclHi = True Then
CountBetw = Application.CountIf(iRange, "" & lowNum) -
Application.CountIf(iRange, "" & hiNum)
End If
End Function

Alan Beban