VBA - Filter 函式



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_arrays.htm
廣告
© . All rights reserved.