How to Count Number of Cells with Dates in Excel (7 Ways)

Let’s use a sample dataset containing Name, Gender, and Date of Birth to showcase how you can count how many cells contain dates in Excel.

count number of cells with dates in Excel


Method 1 – Using the COUNTA Function to Count the Number of Cells with Dates in Excel

Steps:

  • Click on cell F5 and copy the following formula.
=COUNTA(D5:D12)

Count cells with Dates using COUNTA

  • Press Enter.

Here, Excel has counted all the numeric date values ranging from D5 to D12.


Method 2 – Counting Dates in a Given Year Using the Excel SUMPRODUCT Function

Let’s count how many cells fall into specific years. We’ll use two helped columns, with the first containing the years from the range and the other showing the results.
Steps:

  • Click on cell F5 and copy the following formula:
=SUMPRODUCT(--(YEAR($D$5:$D$12)=$F5))

Count cells with Dates by SUMPRODUCT Function

  • Press Enter.

  • AutoFill by dragging down the right button on the mouse.

Count cells with Dates in Excel by FormulaThe YEAR function will extract all the years from the valid date range D5:D12, and the equals operand will match it with the year given in cell F5.

=SUMPRODUCT(--(YEAR(1995;1994;1993;1992)=1992))

To get an array of TRUE and FALSE, each date is compared to the year value in Column D.

={FALSE;FALSE;FALSE;FALSE;TRUE;FALSE;FALSE;TRUE}

This will count the TRUE which is 2 in the case of the year 1992.
Once we use the AutoFill, the criteria value gets changed to the respective cell in the helper column.


Method 3 – Combining Excel Functions to Count the Number of Cells with Dates

Steps:

  • Click on cell F5 and copy the following formula.
=SUM(IF(ISERROR(DATEVALUE(TEXT(D5:D12, "dd/MM/yyyy"))), 0, 1))

count number of cells with dates in Excel

  • Press Ctrl + Shift + Enter altogether. If you’re using Excel 365, pressing Enter will do.

Here the ISERROR function will check whether the cells have number values. It will output FALSE if the cell is not blank and TRUE for blank cells. Then, the IF function will SUM 1 for each FALSE value and 0 for TRUE.


Method 4 – Counting Dates in Current Month Using the COUNTIFS Function

We have a dataset where dates of joining are given. We want to see how many dates are in the current month and how many are in the previous month.

Count cells with Dates for current and previous month in Excel
Steps:

  • Click on cell G5 and copy the formula below:
=COUNTIFS(D5:D12,">="&EOMONTH(TODAY(),-1)+1,D5:D12,"<"&EOMONTH(TODAY(),0)+1)

  • Press Enter.

count number of cells with dates for current month

  • In cell H6, copy the following formula.
=COUNTIFS(D5:D12,">="&EOMONTH(TODAY(),-2)+1,D5:D12,"<"&EOMONTH(TODAY(),-1)+1)

  • Hit Enter.

This formula relies on the COUNTIFS function to count dates that are greater than or equal to the current month’s first day and less than the next month’s first day. Both dates are created using the EOMONTH function, which takes the current date from the TODAY function.


Method 5 – Computing Birthdays by Month Using the SUMPRODUCT Function

Steps:

  • Copy the following formula in cell G5.
=SUMPRODUCT(--(MONTH($D$5:$D$12)=MONTH($F5&1)))

count number of cells with dates in Excel

  • Press Enter.

Count Birthdays by month

  • Drag down to AutoFill for the rest of the series.

Count cells with birthdates


Method 6 – Creating a User Defined Function to Count the Number of Cells with Dates

Steps:

  • Go to the Developer tab from the ribbon.
  • Click on Visual Basic from the Code category to open the Visual Basic Editor or press Alt + F11.

  • Click on Module from the Insert drop-down menu bar. This will create a Module in your workbook.

  • Copy and paste the VBA code shown below:

VBA Code:

Option Explicit
Function Count_DateCells(dRanges As Range) As Integer
Dim drng As Range
Dim dcount As Integer
Application.Volatile
dcount = 0
For Each drng In dRanges
If IsDate(drng) Then
dcount = dcount + 1
End If
Next
Count_DateCells = dcount
End Function
  • Press Ctrl + S to save the file.

  • Go back to your worksheet and insert this formula in the result cell.
=Count_DateCells(D5:D12)
  • Press Enter.


Method 7 – Applying a VBA Macro Tool to Count the Number of Cells with Dates

Steps:

  • Right-click on the sheet and go to View Code.

count number of cells with dates in Excel VBA

  • Copy and paste the VBA code below:

VBA Code:

Option Explicit
Function Date_Count(dRanges As Range) As Variant
Dim dCell() As Variant
Dim rg As Range
Dim dcnt As Integer
Application.Volatile
ReDim dCell(dRanges.Cells.Count - 1) As Variant
dcnt = 0
For Each rg In dRanges
dCell(dcnt) = VarType(rg)
dcnt = dcnt + 1
Next
Date_Count = dCell
End Function

  • Press F5 or the Play button to run the code.
  • Enter this formula in cell F5:
=SUM(IF(Date_Count(D5:D12)=7,1,0))
  • Press the Ctrl + Shift + Enter keys to apply it.

This function will check date values in a given array or ranges and SUM them one by one if the date value is valid.


Download Practice Workbook


<< Go Back to Count Cells | Formula List | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Mahbubur Rahman
Mahbubur Rahman

MAHBUBUR RAHMAN is a leather engineer with a talent for Excel and a passion for VBA programming. To him, programming is like a time-saving wizard, making data manipulation, file handling, and internet interactions a breeze. His skill set extends to SPSS, STATA, Deep Neural Networks, and Machine Learning. Holding a B.Sc in Leather Engineering from Khulna University of Engineering & Technology, he's shifted to become a content developer. In this role, he crafts technical content centred around Excel... Read Full Bio

4 Comments
  1. The SUMPRODUCT was exactly what I needed and I’d never used it before.

    Thanks

  2. Your vba code is too complex. Your code outputs an array that has to be fed further into a complex formula and you didn’t explain why do we have to use 7,1,0 with SUM IF.

    Instead I would prefer to use isDate() function inside the loop to check the cells for being an actual date and increment the count variable each time you get a TRUE result. Finally return a count of cells containing the date instead of an array which will have to be used with more functions.

    Simplicity should be the key. The code should be like this as per my suggestion;

    Function Count_DateCells(dRanges As Range) As Integer

    Dim drng As Range
    Dim dcount As Integer

    Application.Volatile

    dcount = 0

    For Each drng In dRanges

    If IsDate(drng) Then
    dcount = dcount + 1

    End If

    Next

    Count_DateCells = dcount

    End Function

    • Hello, EHTISHAM SAFDAR!
      Thanks a ton for your suggestion!
      In Method-7, the precise range we require to count the number of cells containing dates is D5:D12. Determines whether each data value in a given array or range is legitimate by SUM each one.

      Regards,
      Sabrina Ayon
      Author, ExcelDemy
      .

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo