Separate Delimited String

You need to paste a column of delimited data. You could use Excel's Text to Columns, but you need only an element or two from each cell. Text to Columns parses the entire thing. What you need is a function that lets you specify the number of the element in a string that you need, as shown in Figure 4.13. StringElement(str,chr,ind)

The arguments are str—The string to be parsed. chr—The delimiter.

ind—The position of the element to be returned.

Function example:

Function StringElement(str As String, chr As String, ind As Integer)

Dim arr_str As Variant arr_str = Split(str, chr)

StringElement = arr_str(ind - 1)

End Function

Figure 4.13

Extracting a single element from delimited text.

Figure 4.13

Extracting a single element from delimited text.

0 0

Post a comment