Function使用插入-过程,选择“函数”,就插入一个
[Public|Private] [Static] Function [函数名]([参数列表]) [As 数据类型]
'|As可以定义函数返回值的数据类型
<语句块>
<函数名=过程结果> '函数名必须是最后输出结果
[Exit Function]
[语句块]
[函数名=过程结果]
End Function
统计函数单元格颜色
Function CountColor(arr As Range) '参数是一个Range变量
Dim rng As Range '定义一个Range循环变量
For Each rng In arr '循环每一个arr的单元格,将arr传递给rng
If rng.Interior.Color=RGB(255,255,0) Then '判断rng的底纹颜色是否为黄色
CountColor = CountColor + 1 '让CountColor值加1
End if
Next rng
End Function