【问题标题】:Excel - How to count cells depending on its color and the color of an adjacent cell?Excel - 如何根据单元格的颜色和相邻单元格的颜色计算单元格?
【发布时间】:2016-11-17 16:31:47
【问题描述】:

我正在 Excel 中创建日历/计划工作簿。 所有工作日都是蓝色的,周末是红色的。

我需要做的一件事是计算某个人工作了多少个工作日(蓝色单元格),但没有星期五(还有蓝色单元格,但高于红色单元格(星期六))。

计算一个人工作的工作日总数(蓝色单元格)是没有问题的:

 Function CountCcolor(range_data As Range, criteria1 As Range, criteria2 As Range) As Long
    Dim datax As Range
    Dim xcolor As Long
xcolor = criteria1.Interior.ColorIndex
radiologist = criteria2.Value
For Each datax In range_data
    If datax.Interior.ColorIndex = xcolor And datax.Value = radiologist Then CountCcolor = CountCcolor + 1
    End If
Next datax
End Function

这包括周五,我不想要。

是否可以扩展此代码以排除恰好在红色单元格上方的所有蓝色单元格?

【问题讨论】:

  • 如果是工作日或周末,为什么不使用 Weekday() 测试基础日期。
  • 如果必须基于颜色,您可以在 if 语句中添加 and datax.offset(-1,0)<> ycolour 以查看上面的单元格。

标签: excel excel-formula


【解决方案1】:

使用Range.Offset property 检查循环中单元格正下方的单元格。

For Each datax In range_data
    If datax.Interior.ColorIndex = xcolor And _
       datax.OFFSET(1, 0).Interior.ColorIndex = xcolor And _
       datax.Value = radiologist Then
        CountCcolor = CountCcolor + 1
    End If
Next datax

【讨论】:

    猜你喜欢
    • 2013-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-25
    • 2013-04-17
    相关资源
    最近更新 更多