Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I simulate the VB Split function in VBA?

Functions

How do I simulate the VB Split function in VBA?

by  bustell  Posted    (Edited  )
I have on numerous occasions wondered why the VB Split function was not include in VBA. Here is a function that works with Access to simulate the built in VB Split function:

Public Function Split(ByVal sString As String _
, sDelimiter As String _
, Optional iCompare As Long
= vbBinaryCompare) As Variant

Dim sArray() As String, iArrayUpper As Integer _
, iPosition As Integer
iArrayUpper = 0
iPosition = InStr(1, sString, sDelimiter, iCompare)
Do While iPosition > 0
ReDim Preserve sArray(iArrayUpper)
sArray(iArrayUpper) = Left$(sString, iPosition - 1)
sString = Right$(sString, Len(sString) - iPosition)
iPosition = InStr(1, sString, sDelimiter, iCompare)
iArrayUpper = iArrayUpper + 1
Loop
ReDim Preserve sArray(iArrayUpper)
sArray(iArrayUpper) = sString
Split = sArray

End Function
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top