VBA: User Defined Function that Counts Selected Cells
October 4th, 2008
| Categories: Cells, Columns & Rows
| Tags: cells, count, selected, user defined, VBA
-->
The following function will examine a range of Excel cells and return the number that fall within a specified range:
Function Count_Selected_Cells(Data_Range As Range, Min As Double, Max As Double) As Integer
Dim Cell
Count_Selected_Cells = 0#
For Each Cell In Data_Range
If ((Cell.Value >= Min) And (Cell.Value <= Max)) Then
Count_Selected_Cells = Count_Selected_Cells + 1
End If
Next Cell
End Function
It can be used as:
=Count_Selected_Cells(B5:F14,12,50)
Will return the number of cells having values between 12 and 50 in the range B5:F14:

To download the .XLSM file from the article, click here
Can't get the tutorial to work for you? Need help with your code?
Get answers right away at our AE Excel Support Forums!
Get answers right away at our AE Excel Support Forums!
Leave a comment
| Trackback


