logo
search
Function Problems

How to Count Excel Cells Containing Time Slots with a Formula

Maira MehtabMaira Mehtab Sep 22, 2026 868 views

Question details

The user needs a method to count the number of cells in an Excel range that contain time values falling within a specified time frame, such as between 6:30 AM and 2:30 PM.

Product
Excel
Device & OS
not provided
Scenario
Performing data analysis or tracking employee hours where occurrences within specific daily time periods need to be tallied.
Observed behavior
Requires a reliable formula to extract and count cells based on time boundaries, regardless of associated date data.
Before you start

Ensure that the cells you are analyzing are formatted as actual Excel time values rather than text strings, as the calculation requires valid date/time serial numbers to evaluate the conditions correctly.

Solution 1Recommended

Use the SUMPRODUCT and MOD Functions

Apply a combination formula using SUMPRODUCT and MOD to evaluate and count cells falling within the specified time bounds.

Excel stores dates and times as numerical serial values where one full day equals 1. To calculate times regardless of the date attached to them, the MOD function divides the serial number by 1 and returns just the decimal remainder, representing the time of day. The SUMPRODUCT function then checks these time values against your upper and lower limits and adds up the total matching cells.

1
Select the destination cell

Click on the empty cell where you want the final count result to appear.

2
Enter the SUMPRODUCT formula

Type `=SUMPRODUCT((MOD(A1:A10,1)>=6.5/24)*(MOD(A1:A10,1)<=14.5/24))` into the formula bar.

3
Adjust the cell range

Replace `A1:A10` in both parts of the formula with the actual range of your dataset.

4
Define your specific time slots

Modify `6.5` to your desired start hour (e.g., 6.5 means 6:30 AM) and `14.5` to your end hour (e.g., 14.5 means 2:30 PM). Since there are 24 hours in a day, dividing by 24 converts these hours into the proper time fraction.

5
Calculate the result

Press Enter. The cell will now display the total count of cells that contain times within the specified boundaries.

Formula Returns 0: If your formula returns 0 unexpectedly, select your data range, navigate to the Home tab, and verify that the number format is set to 'Time'. Text-formatted times will not trigger the mathematical conditions in the SUMPRODUCT array.
Use WPS Spreadsheet for Data Analysis

Effortlessly Manage Time Data with WPS Spreadsheet

WPS Spreadsheet fully supports advanced array formulas like SUMPRODUCT and MOD. Whether you are tracking shifts, analyzing schedules, or managing complex datasets, WPS provides a fast and intuitive environment to get your work done.

  1. 1. Open your workbook in WPS Spreadsheet: Launch WPS Office and open your file containing the time records.
  2. 2. Verify data formats: Highlight your time data, right-click, select 'Format Cells', and ensure the 'Time' category is applied.
  3. 3. Insert the array formula: Select an empty cell, paste the SUMPRODUCT and MOD formula, and press Enter to instantly see your time slot counts.
100% compatible with Microsoft Excel (.xlsx, .xls) formulas and formatting.Intuitive cell formatting options to easily convert text to actual time values.Completely free to use, featuring a lightweight installation and fast performance.
microsoft office alternative - wps office

Frequently Asked Questions

Can I use the COUNTIFS function instead of SUMPRODUCT?

Yes, if your cells contain only time values without any dates, you can use a formula like `=COUNTIFS(A1:A10, ">="&TIME(6,30,0), A1:A10, "<="&TIME(14,30,0))`. However, if your cells contain full date-time stamps, COUNTIFS will fail, and you must use the SUMPRODUCT and MOD method to ignore the dates.

How do I change the time range to 8:00 AM to 5:00 PM?

To set the range from 8:00 AM to 5:00 PM, adjust the numeric values in the formula. Replace `6.5/24` with `8/24`, and replace `14.5/24` with `17/24` (since 5:00 PM is 17:00 in military time).

What does the MOD function specifically do in this formula?

The MOD function divides the underlying serial number of the cell by 1 and returns the remainder. Since Excel stores dates as whole numbers and times as fractions of a day, dividing by 1 effectively removes the date portion, leaving only the time for an accurate comparison.

Why is my formula treating my time slots as text strings?

Sometimes imported data or user input is stored as text rather than a calculable number. You can fix this by typing '1' in an empty cell, copying it, selecting your time range, right-clicking to choose 'Paste Special', selecting 'Multiply', and clicking OK to force Excel to convert them into numbers.