Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Counting Times within a Range.

# Counting Times within a Range

by Allen Wyatt
(last updated September 22, 2015)

William has a list of times in column A. He needs a way to find how many of the times fall within a time range, such as between 8:30 am and 9:00 am. He tried using COUNTIF and a few other functions, but couldn't get the formulas to work right.

There are actually a few different ways you can count the times within the desired range, including using the COUNTIF function. In fact, here are two different ways you could construct the formula using COUNTIF:

```=COUNTIF(A1:A100,">="&TIME(8,30,0))-COUNTIF(A1:A100,">"&TIME(9,0,0))
=COUNTIF(A1:A100,">=08:30")-COUNTIF(A1:A100,">09:00")
```

Either one will work fine; they only differ in how the starting and ending times for the range are specified. The key to the formulas is to grab a count of the times that are greater than the earliest boundary of the range and then subtract from that the times that are greater than the upper boundary.

You could also use the SUMPRODUCT function to get the desired result, in this manner:

```=SUMPRODUCT(--(A1:A100>=8.5/24) * --(A1:A100<=9/24))
```

This approach only works if the values in the range A1:A100 contain only time values. If there are dates stored in the cells as well, then it may not work because of the way that Excel stores dates internally. If the range does include dates, then you need to modify the formula to take that into account:

```=SUMPRODUCT(--(ROUND(MOD(A1:A100,1),10)>=8.5/24) * --(ROUND(MOD(A1:A100,1),10)<=9/24))
```

Finally, you could skip formulas altogether and use Excel's filtering capabilities. Apply a custom filter and you can specify that you only want times within the range you need. These are then displayed and you can easily count the results.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12397) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Counting Times within a Range.

##### Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

##### MORE FROM ALLEN

Marking Multiple Documents

After using Word for a while, it is easy to accumulate quite a few documents. At some point you may want to make a change ...

Discover More

Comparing Workbooks

Do you need to compare two workbooks to each other? While you can use specialized third-party software to do the ...

Discover More

What is a Desktop.ini File?

When browsing through your system, you might see several files named Desktop.ini. This tip explains what these files are ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

Converting Time Notation to Decimal Notation

Want to convert an elapsed time, such as 8:37, to a decimal time, such as 8.62? If you know how Excel stores times ...

Discover More

Displaying a Result as Minutes and Seconds

When you use a formula to come up with a result that you want displayed as a time, it can be tricky figuring out how to ...

Discover More

Combining and Formatting Times

Excel allows you to store times in your worksheets. If you have your times stored in one column and an AM/PM indicator in ...

Discover More
##### Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 4 + 4?

2017-12-29 22:48:38

Timothy Partridge

I am trying to count a time range with the cell format of m/d hh:mm. The range I need to count is occurrences between 00:00 and 15:00. The date is not important for this count. I have tried several countif, countifs, sum and sumproduct formulas. The only time they work is if I strip out the date; however the date is needed.

2012-12-31 00:56:32

Asoka Walpitagama

You may also use COUNTIFS function as given below:

=COUNTIFS(A1:A100,"<9:00",A1:A100,">8:30")

Asoka Walpitagama
MS Office Trainer
Sri Lanka

2012-12-30 08:07:41

Michael Avidan - MVP

No need for the "Double Minus sins" because True * True = 1 and True * False = 0.

Therefor:

=SUMPRODUCT((A1:A100>=8.5/24)*(A1:A100<=9/24))

is more than enough.

Michael Avidan
“Microsoft®” MVP – Excel
ISRAEL

##### This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.