问题
I have following date values (with time) in Column A.
1/1/2012 8:50
1/1/2012 8:45
1/1/2012 8:55
1/1/2012 8:59
1/1/2012 8:12
3/1/2012 8:30
1/1/2012 9:50
2/1/2012 10:00
Now, I want to get a count of cells from Column A having date values of current Month.
I have thought of following formula, but I suspect it will work only in machines having mm-dd-yyyy as System-Date-Format.
=COUNTIFS(A:A,">="&DATEVALUE(MONTH(TODAY())&"-1"&"-"&YEAR(TODAY())),A:A,"<"&DATEVALUE(MONTH(TODAY())+1&"-1"&"-"&YEAR(TODAY())))
Any workaround/trick for this?
回答1:
You can use COUNTIFS for current month like this
=COUNTIFS(A:A,">="&EOMONTH(TODAY(),-1)+1,A:A,"<"&EOMONTH(TODAY(),0)+1)
回答2:
Try this: =SUM(IF(MONTH(TODAY())=MONTH(A:A),1,0))
, but press CTRL+SHIFT+ENTER instead of usual ENTER - this will define an ARRAY formula and will result in {}
brackets around it (but do NOT type them manually!).
Put the formula in ANY cell you like.
回答3:
An alternative to the array formula would be to use SUMPRODUCT()
:
=SUMPRODUCT(--(MONTH(A:A)=MONTH(TODAY())))
The --
part is necessary: it turns an array of TRUE/FALSE values into numbers. The double-negative is needed to get a positive value: =VALUE(TRUE)
gives an error, =VALUE(-TRUE)
gives -1
, so =VALUE(--TRUE)
gives +1
.
来源:https://stackoverflow.com/questions/14747689/count-date-values-of-current-month-ms-excel