[英]How to count the colored number of cells in excel
我对在Excel中计算相似的彩色单元格感兴趣。 我尝试使用VB脚本,每当我关闭工作表时,计算就会丢失。
任何人都可以帮助我。
某处(可能的来源- http://www.ozgrid.com/VBA/sum-count-cells-by-color.htm )我发现这个代码,以帮助我:
Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
Dim rCell As Range
Dim lCol As Long
Dim vResult
lCol = rColor.Interior.Color
If SUM = True Then
For Each rCell In rRange
If rCell.Interior.Color = lCol Then
vResult = WorksheetFunction.SUM(rCell)
End If
Next rCell
Else
For Each rCell In rRange
If rCell.Interior.Color = lCol Then
vResult = 1 + vResult
End If
Next rCell
End If
ColorFunction = vResult
End Function
该函数接受有色单元格和范围,以查找具有相似颜色的单元格。 该函数根据颜色返回找到的单元格数。 可以避免使用可选参数“ SUM”(老实说,我自己没有使用过)。 您只需在单元格中键入“ = ColorFunction”,并在括号中填充所需的参数即可:
例如= ColorFunction(C3,A1:Q114)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.