首先,wps和EXCEL里面是没有这个功能的,要实现这个功能需要先启用宏,并在开发工具里面打开VB编辑器,在左边右键点击需要自定义函数的工作表名称,点插入模块,在模块1中输入以下代码
Function CountColor(col As Range, countrange As Range) As Integer
Dim iCell As Range
Application.Volatile
For Each iCell In countrange
If iCell.Interior.ColorIndex = col.Interior.ColorIndex Then
CountColor = CountColor + 1
End If
Next iCell
End Function
然后关闭此页面,返回工作表,点击工具--宏--安全性--安全级--低--确定。WPS2019可以直接用,EXCEL低版本需要保存并关闭工作表,重新打开就可以使用COUNTCOLOR函数了。
更多EXCEL使用技巧,微信公众号:ylxny8同步分享中