A Split Procedure
Splits a string into an array. If you send a " " it will split all the words into each array position.
Original Author: Paul Spiteri
Inputs
The string to split.
The splitter, e.g. " "
Assumptions
Private Sub Command1_Click()
Dim SplitReturn As Variant
SplitReturn = Splitter(Text1.Text, " ")
MsgBox SplitReturn(1)
End Sub
Returns
Returns an array of the results.
Code
Public Function Splitter(SplitString As String, SplitLetter As String) As Variant
ReDim SplitArray(1 To 1) As Variant
Dim TempLetter As String
Dim TempSplit As String
Dim i As Integer
Dim x As Integer
Dim StartPos As Integer
SplitString = SplitString & SplitLetter
For i = 1 To Len(SplitString)
TempLetter = Mid(SplitString, i, Len(SplitLetter))
If TempLetter = SplitLetter Then
TempSplit = Mid(SplitString, (StartPos + 1), (i - StartPos) - 1)
If TempSplit <> "" Then
x = x + 1
ReDim Preserve SplitArray(1 To x) As Variant
SplitArray(x) = TempSplit
End If
StartPos = i
End If
Next i
Splitter = SplitArray
End Function
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.