Option Explicit
Sub Test_ParseText()
Dim I As Integer, NW As Integer
Dim Cel As Range
Dim strBuffer As String, strVal As String, Words(32) As String
For Each Cel In Selection
strVal = Cel.Text
Call ParseText(strVal, " ", NW, Words)
strBuffer = ""
For I = 1 To NW
strBuffer = strBuffer & I & " " & Words(I) & vbCrLf
Next I
MsgBox "original text = " & strVal & vbCrLf & _
"# individual words parsed = " & NW & vbCrLf & _
" individual parsed words:" & vbCrLf + strBuffer, vbInformation
Next Cel
End Sub
Sub ParseText(strBuffer As String, Delim As String, NW As Integer, Words)
Dim strItems() As String
Dim Item As Variant
strItems = Split(strBuffer, Delim)
NW = 0
For Each Item In strItems
NW = NW + 1
Words(NW) = Item
Next
End Sub
|