自定义函数的参数
-
固定函数
GIF.gif
Public Function colorcount()
If Range("a1").Interior.ColorIndex = 6 Then
colorcount = 1
Else
colorcount = 0
End If
End Function
注意colorcount=0不可少,因为当A1单元格的颜色不是黄色的时候会报错。
-
固定区域函数
GIF.gif
Public Function colorcount()
Dim rng As Range
For Each rng In Range("a1:a10")
If rng.Interior.ColorIndex = 6 Then
colorcount = colorcount + 1
End If
Next
End Function
-
可选区域函数
GIF.gif
Public Function colorcount(arr As Range)
Dim rng As Range
For Each rng In arr
If rng.Interior.ColorIndex = 6 Then
colorcount = colorcount + 1
End If
Next
End Function
-
两个参数
GIF.gif
Public Function colorcount(arr As Range, c As Range)
Dim rng As Range
For Each rng In arr
If rng.Interior.ColorIndex = c.Interior.ColorIndex Then
colorcount = colorcount + 1
End If
Next
End Function
-
不定参数
GIF.gif
Function joins(ParamArray arr())
For Each ar In arr
For Each a In ar
txt = txt & a.Value
Next
Next
joins = txt
End Function
注意:
1.如果参数不定,那么不能指定参数的数据类型
2.如果有不定参数,不定参数一定要写在最后。
网友评论