How to count if cells contain any date/data in Excel?
Have you even met problems to count number of cells containing any date or data in a specific range in Excel? In this article, I will introduce ways to count if cells contain any date/data in Excel.
Count and select cells if contains any data in a specified range (only one click)
Recommended Productivity Tools for Excel
Office Tab: Bring powerful tabs to Office (include Excel), just like Chrome, Safari, Firefox and Internet Explorer. Save you half the time, and reduce thousands of mouse clicks for you. 30-day Unlimited Free Trial
Kutools for Excel: Save 71% of your time and solve 82% Excel problems for you. 300+ advanced tools designed for 1500+ work scenario, make Excel much easy and increase productivity immediately.60-day Unlimited Free Trial
This method will introduce a VBA Macro to count cells containing dates in a specific range in Excel.
Step 1: Open the Microsoft Visual Basic for Applications window with pressing the Alt + F11 keys at the same time.
Step 2: Click the Insert > Module, and then paste the following VBA code into the Module window:
VBA: Count if cells contain any date
Function TypeCell(pRange As Range) As Variant
Dim xArr() As Variant Dim xRng As Range Application.Volatile ReDim xArr(pRange.Cells.Count - 1) As Variant xCount = 0 For Each xRng In pRange xArr(xCount) = VarType(xRng) xCount = xCount + 1 Next TypeCell = xArr End Function
Step 3: In a blank cell enter the formula =SUM(IF(TypeCell(A1:E15)=7,1,0)), and then press the Ctrl + Shift + Enter keys in a meantime.
Note: In the formula of =SUM(IF(TypeCell(A1:E15)=7,1,0)), the A1:E15 is the specific range we will count number of cells containing dates, you can change it based on your needs.
Now you will get the number of cells containing dates in the specific range.
The COUNTA function will help you figure out the number of cells with any data in a specific range in Excel easily.
In a blank cell enter the formula =COUNTA(A1:E15), and press the Enter key. In the formula, the range A1:E15 is the specific range you will count numbers of cells with data, and you can change it as you need.
Note: After selecting the specific range, we can get the cell number with any data in the Status Bar easily too.
If you have Kutools for Excel installed, you can apply its Select Nonblank Cells utility to count and select cells if contains any data quickly in a certain range with only one click.
Kutools for Excel - Combines more than 300 Advanced Functions and Tools for Microsoft Excel
And then all cells with data in the specified range are selected, and a dialog box will pop up and show how many nonblank cells have been selected. See screenshot:
Click the OK button to close this dialog box.