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 Dates in a Range.
Written by Allen Wyatt (last updated August 26, 2021)
This tip applies to Excel 97, 2000, 2002, and 2003
If you have a range of cells that are filled with random, non-sorted dates, you may want to figure out how many of those dates fall between a start date and an end date. For instance, if B1:B101 contains the random dates, cell E1 contains the start date, and cell E2 contains the end date, you may want to know what type of formula you can use in cell E4 to return the number of dates in B1:B101 that fall between E1 and E2.
There are actually several different ways you can arrive at a solution. The first, of course, would be to simply add a formula in each cell to the right of the dates in column B, and have that formula return a 1 if the date is between E1 and E2, or a 0 if not. You could then sum the column to get the desired count. You would use the following formula in each cell to the right of the dates:
=IF(AND(B1>=E$1,B1<=E$2),1,0)
This particular formula goes into cell C1, and can then be copied down to cells C2 through C101. Then, in cell E4, all you would need to do is use the following formula:
=SUM(C1:C101)
The drawback to this, of course, is that the additional values in C1:C101 can play havoc with the appearance of a carefully crafted worksheet. Fortunately there are ways to find the proper result without the need to use an intermediate value.
One way is to use an array formula. The following formula, placed in cell E4, will do the trick. All you need to do is remember to enter the formula using Shift+Ctrl+Enter. (This signifies to Excel that you are entering an array formula.)
=COUNT(IF((B1:B101>$E$1)*(B1:B101<$E$2),B1:B101))
If you prefer to not use an array formula, you can use the following standard COUNTIF-based formula in E4:
=-COUNT(B1:B101)+COUNTIF(B1:B101,">"&E1)+COUNTIF(B1:B101,"<"&E2)
When you enter this formula, Excel will assume that you are returning a date value, and will therefore helpfully format the cell as a date. All you need to do to correct this is to use Format | Cell to format the cell using something besides a date format, such as General.
The formula works by counting all dates that are after the early date plus all dates that are before the late date. This essentially counts all dates once and double-counts the desired selection. By subtracting the number of dates in the range (at the beginning of the formula), the formula effectively eliminates all but the desired result.
If you prefer, you can also use the DCOUNT function to return the desired count. This, however, is just a bit more involved. Unlike the earlier solutions, DCOUNT relies on the use of named ranges. Follow these steps:
=DCOUNT(MyDates,1,D1:E2)
The DCOUNT function uses the criteria you specified in D1:E2 to examine the data range defined as MyDates and return the count of cells that meets those criteria.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2818) 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 Dates in a Range.
Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!
When you load data into Excel that was created in other programs, the formatting used for some types of data (such as ...
Discover MoreDon't want to use the EOMONTH function to figure out the end of a given month? Here are some other ideas for discovering ...
Discover MoreNeed to know how many days there are between two dates? It's easy to figure out—unless you need the figure in ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2017-02-27 09:34:26
Rkeev
David, Use a Pivot table, it will count what you want.
2013-12-16 12:00:41
I have table with about 2000 rows which contains a cell for date of a job, ther person who completed it, and other information in that row, per job.
I'm trying to build a chart next to it which gives me a count of the number of jobs per month, and a count of the number of jobs for each person per month.
i'm finding a lot of other date criteria formulas for excel, but haven't found this one yet.
Any help?
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments