Filter()
函數返回一個基於零的數組,其中包含基於特定過濾條件的字串數組的子集。
語法
Filter(inputstrings,value[,include[,compare]])
參數說明
- Inputstrings - 必需的參數。該參數對應於要搜索的字串數組。
- Value - 必需的參數。此參數對應於要根據
inputstrings
參數搜索的字串。 - Include - 一個可選參數。這是一個布爾值,它指示是否返回包含或排除的子字串。
- Compare - 一個可選參數。該參數描述要使用哪種字串比較方法。
- 0 = vbBinaryCompare - 執行二進位比較
- 1 = vbTextCompare - 執行文本比較
例子
添加一個模組,並添加以下代碼 -
Private Sub Constant_demo_Click()
Dim a,b,c,d as Variant
a = array("Red","Blue","Yellow")
b = Filter(a,"B")
c = Filter(a,"e")
d = Filter(a,"Y")
For each x in b
msgbox("The Filter result 1: " & x)
Next
For each y in c
msgbox("The Filter result 2: " & y)
Next
For each z in d
msgbox("The Filter result 3: " & z)
Next
End Sub
當執行上面的函數時,它會產生下麵的輸出。
The Filter result 1: Blue
The Filter result 2: Red
The Filter result 2: Blue
The Filter result 2: Yellow
The Filter result 3: Yellow
上一篇:
VBA數組
下一篇:
VBA用戶自定義函數