SubSplit_Example1()DimMyTextAs StringDimi AsIntegerDimMyResult()As StringMyText = "My Name is Excel VBA"End Sub Step 4:Now, apply the VBA Split String function for the "My Result" variable. Code: SubSplit_Example1()DimMyTextAs StringDimi AsIntegerDimMyResult()As StringMyText = "My Name ...
Dim strText As String Dim strResult() As String strResult =Split(WorksheetFunction.Trim(rngCellRef.Text), " ") GetWordNum = UBound(strResult) + 1 End Function 这样,可以在工作表中像使用Excel内置函数一样使用GetWordNum函数,如下图3所示。 图3 示例3:使用空格字...
FunctionGetWordNum(rngCellRef As Range)Dim strText As String DimstrResult()As String strResult=Split(WorksheetFunction.Trim(rngCellRef.Text)," ")GetWordNum=UBound(strResult)+1End Function 这样,可以在工作表中像使用Excel内置函数一样使用GetWordNum函数,如下图3所示。 图3 示例3:使用空格字符以外的分...
arr=Split(str, ““) 省略最后两个参数(limit和compare,因为它们是可选的)。 接下来的例子使用了limit参数: Sub SplitString2() Dim arr() As String Dim str As String Dim i str = "I am a student" arr = Split(str, " ", 2) For i = 0 To UBound(arr) Debug.Print arr(i) Next End ...
我首先给出SplitA函数过程和标准模块过程的代码:Function SplitA(Text As String, DelimChars As String) As String()'假如源文本是空的,退出函数 Dim Arr() As String If Len(Text) = 0 Then Exit Function End If '假如分隔符是空的,返回源源字符串 If DelimChars = vbNullString Then ReDimArr(0)...
Function SplitB(ByValInString As String, IgnoreDoubleDelmiters As Boolean, _Delims() As String) As String()'IgnoreDoubleDelmiters表示指示当两个delims之间没有文本时要做什么。' 如果该值为True,则将连续分隔符压缩为单个分隔符。' 如果此值为False,则连续分隔符将导致结果数组中的元素为空。Dim Arr()...
Function GetWordNum(rngCellRef As Range) Dim strText As String Dim strResult() As String strResult =Split(WorksheetFunction.Trim(rngCellRef.Text), " ") GetWordNum = UBound(strResult) + 1 End Function 这样,可以在工作表中像使用Excel内置函数一样使用GetWordNum函数,如下图3所示。
Function SplitA(Text As String, DelimChars As String) As String() '假如源文本是空的,退出函数 Dim Arr() As String If Len(Text) = 0 Then Exit Function End If '假如分隔符是空的,返回源源字符串 If DelimChars = vbNullString Then
Public Function Str_2d(str As String, intCol, Optional Delim As String = " ") As Variant Dim Num_Rows As Long Dim arrTemp, arrTemp2 Dim iCount As Integer Dim Row_Count As Integer Dim Col_Count As Integer '确定结果数组的大小和形状 - ...