Open Apps Script
In Google Sheets, open Extensions → Apps Script.
Add the COUNTER function
Add the counter.gs Apps Script code to your project and save it.
Use it in your sheet
Enter =COUNTER(range, inRange) in a cell.
Syntax Reference
=COUNTER(range, inRange)
-
range — The numeric range to analyse,
such as
M:M,M2:M100, orA1:A500. - inRange — The size of each interval. It must be greater than zero.
How It Works
The function finds the numeric values in the supplied range, divides them into consecutive intervals of the specified size, and counts how many values fall into each interval.
Intervals use a lower-inclusive and upper-exclusive boundary.
For example, with an interval of 5:
0 to 5 5 to 10 10 to 15 15 to 20
A value of 5 therefore belongs to 5 to 10,
while a value of 4.99 belongs to 0 to 5.
Examples
=COUNTER(M:M, 5) =COUNTER(M2:M100, 5) =COUNTER(A2:A500, 10) =COUNTER(B2:B1000, 2.5)
Example Result
Interval Count -20 to -15 4 -15 to -10 7 -10 to -5 12 -5 to 0 9 0 to 5 15 5 to 10 8
Notes
- Blank cells are ignored.
- Non-numeric values are ignored.
- The range can be changed directly in the formula.
- The interval size can be changed directly in the formula.
- Negative numbers are supported.
- The function returns both the interval and its count.
Troubleshooting
"#NAME?" error
Make sure the Apps Script containing the COUNTER function
has been saved and is attached to the current Google Sheet.
"#VALUE!" error
Check that the interval argument is a positive number.
For example, =COUNTER(M:M,5) is valid,
while an interval of zero is not.
No results or unexpected counts
Check the supplied range and make sure the cells containing the values are actually numeric values rather than text representations of numbers.