Alegro
Alegro

Reputation: 7956

How to COUNTIFS with cells formatted as date

Excuse me, again about COUNTIFS

Dim a As String    
a = ct.Range("B4").Text ' B4 is formatted as date
Range("C6").Value = Application.WorksheetFunction.CountIfs(rDat, a, rSec, "1")

rDat and rSec are defined ranges (on another sheet).
rDat has the same format as ct.B4 (i.e. date)
I got "0" as a result, but it is wrong.
I tried to remove date format, and format as text - it works.
But I need date format in rDat and B4.

Upvotes: 0

Views: 511

Answers (1)

Artyom Skrobov
Artyom Skrobov

Reputation: 311

Dim a As Date
a = ct.Range("B4") ' do not convert B4 to text
Range("C6").Value = Application.WorksheetFunction.CountIfs(rDat, a, rSec, "1")

Upvotes: 3

Related Questions