By: Ehtisham Safdar

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