- VBA 教程
- VBA - 主頁
- VBA - 概覽
- VBA - Excel 宏
- VBA - Excel 術語
- VBA - 宏註釋
- VBA - 訊息框
- VBA - 輸入框
- VBA - 變數
- VBA - 常量
- VBA - 運算子
- VBA - 決策
- VBA - 迴圈
- VBA - 字串
- VBA - 日期和時間
- VBA - 陣列
- VBA - 函式
- VBA - 子過程
- VBA - 事件
- VBA - 錯誤處理
- VBA - Excel 物件
- VBA - 文字檔案
- VBA - 程式設計圖表
- VBA - 使用者窗體
- VBA 有用資源
- VBA - 快速指南
- VBA - 有用資源
- VBA - 討論
VBA - Split 函式
Split 函式返回一個數組,其中包含根據分隔符拆分的特定數量的值。
語法
Split(expression[,delimiter[,count[,compare]]])
引數說明
Expression − 一個必需的引數。可以包含帶分隔符的字串的字串表示式。
Delimiter − 一個可選引數。用於根據分隔符轉換為陣列的引數。
Count − 一個可選引數。要返回的子字串的數量,如果指定為 -1,則返回所有子字串。
Compare − 一個可選引數。此引數指定要使用哪個比較方法。
0 = vbBinaryCompare - 執行二進位制比較
1 = vbTextCompare - 執行文字比較
示例
新增一個按鈕並新增以下函式。
Private Sub Constant_demo_Click()
' Splitting based on delimiter comma '$'
Dim a as Variant
Dim b as Variant
a = Split("Red $ Blue $ Yellow","$")
b = ubound(a)
For i = 0 to b
msgbox("The value of array in " & i & " is :" & a(i))
Next
End Sub
執行上述函式時,會產生以下輸出。
The value of array in 0 is :Red The value of array in 1 is : Blue The value of array in 2 is : Yellow
vba_arrays.htm
廣告
