【发布时间】: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