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

合并单元格下统计相同面板数量的Excel公式求助

合并单元格面板数量统计方案

基于文本标识的统计方法

如果面板类型通过单元格文本区分(如型号、名称),直接用以下公式即可解决合并单元格统计问题:

  • 通用公式(兼容所有Excel版本):
    =SUMPRODUCT(--(B2:B100=D2),--(NOT(ISBLANK(B2:B100))))
    
    说明:B2:B100是合并单元格所在区域,D2是要统计的目标面板类型。公式仅统计合并单元格的首行(合并单元格仅首行有值,其余为空),避免重复计数。
  • 简化版(Excel 365/2021):
    =SUM(BYROW(B2:B100,LAMBDA(x,IF(AND(x=D2,x<>""),1,0))))
    

基于填充颜色的统计方法

若面板类型通过单元格填充颜色区分,需用自定义VBA函数实现:

  1. 按Alt+F11打开VBA编辑器,插入新模块
  2. 粘贴以下代码:
Function CountColor(rng As Range, refCell As Range) As Long
    Dim targetColor As Long
    Dim cell As Range
    targetColor = refCell.Interior.Color
    For Each cell In rng
        ' 仅统计合并单元格的首行,避免重复计数
        If cell.MergeCells Then
            If cell.Address = cell.MergeArea.Cells(1, 1).Address Then
                If cell.Interior.Color = targetColor Then CountColor = CountColor + 1
            End If
        Else
            If cell.Interior.Color = targetColor Then CountColor = CountColor + 1
        End If
    Next cell
End Function
  1. 返回Excel,使用公式:
=CountColor(B2:B100,E2)

说明:B2:B100是目标区域,E2是对应颜色的参考单元格。需将文件保存为.xlsm格式并启用宏。

关键注意事项

  • 统计区域必须包含所有合并单元格的首行,否则会漏统计
  • 基于颜色的统计需启用宏,若禁用宏则函数失效

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 02:05:14