[英]Excel - How to count cells depending on its color and the color of an adjacent cell?
我正在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
这包括星期五,但我不想要。
是否可以扩展此代码以排除正好在红色单元格上方的所有蓝色单元格?
使用Range.Offset属性可检查循环中一个单元格正下方的单元格。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.