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 ...
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:使用空格字符以外的分...
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:使用空格字...
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 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所示。
SplitC = Arr Exit Function End If '如果分隔符为空 If Len(Delimiter) = 0 Then ReDimArr(0 To 0)Arr(0) = InString Exit Function End If S = InString N = 1 Done = False '查找一个在分隔符中没有的符号作为InGroupReplace Do Until Done 'Chr(N)与Delimiter比较 If StrComp(Chr(N), ...
arArray = VBA.Split(sConCat, sSeparatorChar) ReturnNthElement = arArray(iNumber - 1) EndFunction Splitting between two search terms PublicSubTesting() DimsTextAsString sText = "Be More Productive Using Better Solutions" Debug.PrintTrim(Split(Split(sText, "More")(1), "Better")(0)) ...
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 '确定结果数组的大小和形状 - ...