Google Sheets Custom Function

Count values.
By interval.

A simple Google Sheets custom function that groups numeric values into intervals of any size and counts how many values fall within each interval.

View Setup
Google Sheets
// Count values in column M using intervals of 5

=COUNTER(M:M, 5)

// Or use any range
=COUNTER(A2:A100, 10)

// The function returns interval + count
→ -20 to -15    4
→ -15 to -10    7
→ -10 to -5    12
→ -5 to 0       9
→ 0 to 5       15

Simple

Pass a range and an interval size. The function groups the values and returns their counts.

Flexible

Use any valid numeric range and choose the interval size you need: 1, 5, 10, 2.5, or any positive number.

Handles negatives

Negative values are placed into the correct intervals just like positive values.

1

Open Apps Script

In Google Sheets, open Extensions → Apps Script.

2

Add the COUNTER function

Add the counter.gs Apps Script code to your project and save it.

3

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, or A1: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.

Email

vkdtech@gmail.com
For questions and support

GitHub

github.com/vkdatta
Source code and issues

Frequently Asked Questions

What does COUNTER do?

COUNTER(range, inRange) groups numeric values from the supplied range into intervals of the specified size and returns the number of values in each interval.

Can I change the range?

Yes. The first argument can be any suitable Google Sheets range. For example: =COUNTER(M2:M100,5).

Can I change the interval?

Yes. The second argument determines the interval size. For example, 5 creates intervals of five units, while 10 creates intervals of ten units.

Does it support negative numbers?

Yes. Negative values are grouped into the appropriate intervals.

Does it count blank cells?

No. Blank cells are ignored.

What happens to text?

Non-numeric values are ignored when calculating the interval counts.

How can I report an issue?

Contact vkdtech@gmail.com or visit github.com/vkdatta.

Last updated: August 24, 2026

1. Overview

counter.gs is a Google Apps Script custom function for Google Sheets. It processes the range supplied to the COUNTER() function in order to calculate interval counts.

2. Spreadsheet Data

counter.gs does not operate a separate database or analytics service for storing spreadsheet values. The function operates through the Google Apps Script environment associated with the spreadsheet.

The function only processes the range provided to it for the purpose of calculating the requested interval counts.

3. Personal Information

counter.gs does not intentionally collect personal information through the COUNTER function.

4. Third-Party Services

counter.gs does not intentionally send spreadsheet values to an independent external analytics or advertising service.

5. Google Services

Because counter.gs runs through Google Apps Script, its operation is subject to Google's applicable services, infrastructure, permissions, and privacy practices.

6. Contact

For privacy questions, contact vkdtech@gmail.com.

This privacy policy is effective as of August 24, 2026.

Last updated: August 24, 2026

1. Acceptance of Terms

By using counter.gs, you agree to these Terms of Service. If you do not agree with these terms, do not use the function.

2. Description of Service

counter.gs provides a Google Apps Script custom function:

=COUNTER(range, inRange)

The function groups numeric values from a supplied range into intervals of the specified size and returns the number of values contained in each interval.

3. Use of the Function

You are responsible for how you use the function and for verifying calculations and results that are important to you.

4. Availability

The function is provided on an as-is basis. There is no guarantee that it will always be available, error-free, or compatible with every future version of Google Sheets or Google Apps Script.

5. Intellectual Property

The counter.gs name, website materials, and associated code are protected by applicable intellectual property laws unless otherwise stated.

6. Disclaimer

Results produced by counter.gs should be independently verified when used for financial, business, legal, scientific, or other important purposes.

7. Limitation of Liability

To the extent permitted by applicable law, counter.gs and its operator shall not be liable for losses or damages resulting from the use of, inability to use, or reliance upon the function.

8. Changes

These Terms may be updated from time to time. Continued use of counter.gs after an update constitutes acceptance of the updated terms.

9. Contact

For questions about these Terms, contact vkdtech@gmail.com.

By using counter.gs, you acknowledge that you have read and understood these Terms of Service.