I have a strange problem with Execl. The value of a specific cell ist 01.01.1900
, the format of the cell is date
-Format. When I try to count how many instances of 01.01.1900
there are via CountIf
the result is 0
, the search term is created via CDate()
-conversion. Here's the complete code:
Dim searchterm as Date
Dim someRange as Range
searchTerm = CDate("01.01.1900")
Application.WorksheetFunction.CountIf(someRange, searchTerm)
The whole thing works as expected when the date starts before 01.03.1900
. With the date in question 01.01.1900
I get the following results:
VarType(singleCellRange)
returns 7
(which is date format)
singleCellRange.Value
returns 31.12.1899
(see also here)
So the question is: how do I get the right format for the problematic dates in order to make CountIf
work again?