VBA Split function

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading...

Split Function Description

The VBA Split function splits any string into substrings separated by a given delimiter, returning a VBA Array containing the split substrings.

Syntax

The syntax for the Split function in VBA is:

Split ( expression [,delimiter] [,limit] [,compare] )

Parameters

expression
The string to be split into separate substrings separated by the given delimiter.

delimiter
Optional. The delimiter which separates the expression into separate substrings. By default this is a whitespace character (” “).

limit
Optional. The limit of substrings to be returned by splitting the expression into separate substrings. By default this equals -1 which means all substrings are to be returned.

compare
Optional. The type of comparison to perform when looking for the substring. This can be one of the following VBA Constants:

Constant Value Description
CompareMethod.Binary 0 Binary comparison (distinguishes letter case)
CompareMethod.Text 1 Textual comparison (ignores letter case)

Other Notes

The Split function will return a VBA Array containing the splitted substrings. The numbering of the first item in the VBA Array starts at 0.

Example usage

The Split function can be used in VBA code. Let’s look at some VBA Split function examples:

Split "Hello World!"
'Result: "Hello", "World!"

Split "1.2.3.4.5", "."
'Result: "1", "2", "3", "4", "5"

Simply the best place to learn VBA!