View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Alternative to Split function for Excel97?

Charles,
I give up...

Count = -1
If cntSplit + 1 = Count Then

How could cntSplit ever = -2?
Is this some "left over" code?

Regards,
Jim Cone
San Francisco, CA

"Charles Williams" wrote in message ...
Here is the routine I use, adapted from one found at VBSPEED
(http://www.xbeat.net/vbspeed/c_Split.htm
Its fast enough not to bother with VBA6 split.


Public Function Split5(Expression As String, _
Delimiter As String) As Variant
' by Donald, , 20000916
'
' modified for VBA5 crw 8/10/2004
'
'
Const BUFFERDIM As Long = 1024
Dim cntSplit As Long
Dim posStart As Long
Dim posFound As Long
Dim lenDelimiter As Long
Dim sArray() As String
Dim ubArray As Long
Dim Count As Long

Count = -1

lenDelimiter = Len(Delimiter)
If lenDelimiter = 0 Then
' return expression in single-element Variant array
Split5 = Array(Expression)
Else
posStart = 1
ubArray = -1
Do
If cntSplit ubArray Then
ubArray = ubArray + BUFFERDIM
ReDim Preserve sArray(ubArray)
End If
posFound = InStr(posStart, Expression, Delimiter, vbBinaryCompare)
If cntSplit + 1 = Count Then
sArray(cntSplit) = Mid$(Expression, posStart)
Exit Do
Else
If posFound Then
sArray(cntSplit) = Mid$(Expression, posStart, posFound -
posStart)
posStart = posFound + lenDelimiter
cntSplit = cntSplit + 1
Else
sArray(cntSplit) = Mid$(Expression, posStart)
End If
End If
Loop While posFound
' shrink to actual size
ReDim Preserve sArray(cntSplit)
' return string array as Variant array
Split5 = sArray
End If

End Function


regards
Charles
______________________
Decision Models
FastExcel 2.1 now available
www.DecisionModels.com