Created
July 9, 2014 09:45
-
-
Save batandwa/2b9a072bc2c2f1969faf to your computer and use it in GitHub Desktop.
Excel: Split a string by a delimiter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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