Automatic division of text by the given separator

GETSUBSTR() Description

Below you will find a function that will help you split the text into parts based on the specified separator.

VBA code for the macro

To add a macro, open the editor Visual Basic (Alt+F11), insert a new empty program module (Insert - Module) and copy the text of this function there:

Function GETSUBSTR(Txt, Delimiter, n) As String
   Dim x As Variant
      x = Split(Txt, Delimiter)
      If n > 0 And n - 1 <= UBound(x) Then
        GETSUBSTR = x(n - 1)
        GETSUBSTR = ""
      End If
End Function

Save and return to Excel. Now in custom functions you can find our GETSUBSTR() function.

GETSUBSTR(text; delimiter; fragment sequence number)


Related Articles: