周四,05 2023一月
  1 回复
  3.7K访问
0
投票
解开
在此先感谢您提供的任何帮助。

在这个网站的帮助下,我创建了以下功能;

函数 ColorFunction(rColor 作为范围,rRange 作为范围,可选的 SUM 作为布尔值)
Dim rCell 作为范围
将 lCol 变暗
昏暗的结果
lCol = rColor.Interior.ColorIndex
如果 SUM = True 那么
对于 rRange 中的每个 rCell
如果 rCell.Interior.ColorIndex = lCol 那么
vResult = WorksheetFunction.SUM(rCell, vResult)
结束如果
下一个 rCell
其他
对于 rRange 中的每个 rCell
如果 rCell.Interior.ColorIndex = lCol 那么
v结果 = 1 + v结果
结束如果
下一个 rCell
结束如果
颜色函数 = vResult
函数结束


在每个目标单元格中​​,我想要该行中包含指定单元格颜色的所有单元格的总和;
=颜色函数(AR4,H5:AP5,真)

当行中的任何其他单元格 (H5:AP5) 改变颜色时,如何让目标销售更新?
0
投票
解开
您好,

您可以添加代码: 应用程序.计算 = xlAutomatic 到您的功能:

Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
Dim rCell As Range
Dim lCol As Long
Dim vResult
Application.Calculation = xlAutomatic
lCol = rColor.Interior.ColorIndex
If SUM = True Then
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = WorksheetFunction.SUM(rCell, vResult)
End If
Next rCell
Else
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = 1 + vResult
End If
Next rCell
End If
ColorFunction = vResult
End Function


请试一试。

阿曼达
  • 页:
  • 1
目前还没有回复。