You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改COUNTIF公式仅统计动态区域中的日期单元格

Modified Formula to Count Only Date Cells in Dynamic Range

Alright, let's adjust your formula to only count actual date cells (ignoring text values) in that dynamic range you've set up. Here's how to do it:

Basic Modified Formula

This version keeps your original dynamic range logic but filters for date cells (since dates in Excel are stored as numeric values, we use ISNUMBER to identify them):

=SUMPRODUCT(--ISNUMBER(INDIRECT(ADDRESS(ROW(S4),COLUMN(S4))&":S"&MIN(IF(A4:A107="",ROW(A4:A107))))))

Breakdown of Changes:

  • Replaced COUNTIF with SUMPRODUCT: SUMPRODUCT lets us work with array-based conditions, which we need to check each cell for being a date.
  • --ISNUMBER(...): Converts the TRUE/FALSE result of ISNUMBER into 1/0 values. SUMPRODUCT then sums these up to get the total count of date cells.
  • Removed the -1: Since we're now only counting valid date cells, there's no need to subtract 1 (that adjustment was likely for an extra non-date cell in your original range).

Simplified Version (Excel 365/2021+)

If you're using a modern Excel version with dynamic array support, use the LET function to make the formula cleaner and easier to maintain:

=LET(
    EndRow, MIN(IF(A4:A107="",ROW(A4:A107))),
    DynamicRange, INDIRECT("S"&ROW(S4)&":S"&EndRow),
    SUMPRODUCT(--ISNUMBER(DynamicRange))
)

This splits the formula into named variables (EndRow for the dynamic range's end, DynamicRange for the full range) so you can tweak parts without rewriting the whole formula.

Strict Date Check (Optional)

If you need to exclude numeric values that aren't valid dates (e.g., random numbers), use this version to verify the value is a valid date:

=SUMPRODUCT(--(NOT(ISERROR(DATEVALUE(TEXT(INDIRECT(ADDRESS(ROW(S4),COLUMN(S4))&":S"&MIN(IF(A4:A107="",ROW(A4:A107)))),"mm/dd/yyyy"))))))

This converts the cell value to a text date format and checks if it can be converted back to a valid date, ensuring only actual dates are counted.

Note for Array Formulas

If you're using an older Excel version (pre-365/2021), you'll need to enter the formula as an array formula by pressing Ctrl+Shift+Enter after typing it (instead of just Enter).

内容的提问来源于stack exchange,提问作者Soru Soravic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:26:17