Skip to content

Instantly share code, notes, and snippets.

@batandwa
Created July 9, 2014 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save batandwa/2b9a072bc2c2f1969faf to your computer and use it in GitHub Desktop.
Save batandwa/2b9a072bc2c2f1969faf to your computer and use it in GitHub Desktop.
Excel: Split a string by a delimiter
Function STR_SPLIT(str, sep, n) As String
Dim V() As String
V = Split(str, sep)
If (n < 0) Then
STR_SPLIT = V(UBound(V) + 1 + n)
Else
STR_SPLIT = V(n - 1)
End If
End Function
Sub Test()
Dim val As String
MsgBox (STR_SPLIT("aaaa/bbbbb/ccccc/ddddd/eeeeee", "/", 1))
MsgBox (STR_SPLIT("aaaa/bbbbb/ccccc/ddddd/eeeeee", "/", 4))
MsgBox (STR_SPLIT("aaaa/bbbbb/ccccc/ddddd/eeeeee", "/", -1))
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment