COUNTBETWEEN

COUNTBETWEEN(rgeValues, minValue, maxValue, bInclusive)
Counts number of values between value1 and value2

rgeValues
minValue
maxValue
bInclusive

REMARKS
* The values can be numbers or dates.
* You can use the built-in COUNT function to
* You can use the user defined COUNTFORMAT function to
* You can use the user defined COUNTSUBSTRING function to
* Similar to the user defined functions MAXBETWEEN, MINBETWEEN, SUMBETWEEN and ISBETWEEN
Public Function COUNTBETWEEN( _

Public Function COUNTBETWEEN( _ 
         ByVal rgeValues As Range, _
         ByVal minValue As Single, _
         ByVal maxValue As Single, _
Optional ByVal bInclusive As Boolean = True) _
         As Variant

Dim objcell As Range
Dim itotalcells As Integer

    itotalcells = 0
    
    If (rgeValue.Cells.Count > 10000) Then
       COUNTBETWEEN = "no column references"
       Exit Function
    End If
    
    If (bInclusive = True) Then
      For Each objcell In rgeValue
         If (objcell.Value >= minValue) And (objcell.Value <= maxValue) Then
            itotalcells = itotalcells + 1
         End If
      Next objcell
    End If
    
    If (bInclusive = False) Then
      For Each objcell In rgeValue
         If (objcell.Value > minValue) And (objcell.Value < maxValue) Then
            itotalcells = itotalcells + 1
         End If
      Next objcell
    End If
    
    COUNTBETWEEN = itotalcells
End Function

For instructions on how to add this function to a workbook refer to the page under Inserting Functions


© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext