Hi,
Here is one way to do it. Place these functions in a standard module:
Public Function CountChar(strIn As String, CharToCount As String) As Integer
Dim i As Integer
Dim intPointer As Integer
intPointer = 1
Do While i <= Len(strIn)
If InStr(intPointer, strIn, CharToCount, vbTextCompare) <> 0 Then
i = i + 1
intPointer = InStr(intPointer, strIn, CharToCount, vbTextCompare) + 1
Else
Exit Do
End If
Loop
CountChar = i
End Function
Public Sub ParseString(expression As String, delimiter As String, arr() As String)
Dim charCount As Integer
Dim strTemp As String
Dim pos As Integer
Dim i As Integer
charCount = CountChar(expression, delimiter)
ReDim arr(0 To charCount)
strTemp = expression
Do
arr(i) = Left(strTemp, InStr(1, strTemp, delimiter, vbTextCompare) - 1)
strTemp = Mid(strTemp, InStr(1, strTemp, delimiter, vbTextCompare) + 1)
i = i + 1
Loop Until InStr(1, strTemp, delimiter, vbTextCompare) = 0
arr(i) = strTemp
End Sub
Then you can call it like so:
Dim myArr() As String
Dim i As Integer
ParseString "hi,there,you", ",", myArr()
For i = 0 To UBound(myArr)
MsgBox myArr(i)
Next
The MsgBox stuf was just for testing. The 1st argument to the ParseString function is the string
you want parsed, the 2nd is your delimiter and the 3rd is the array where the broken up string
will be placed.