In this tutorial you will learn how to use the Split Function.
The Split Function returns a zero-based, one-dimensional array containing a specified number of substrings.
=Split(Expression As String, [Delimiter], [Limit As Long = -1], [Compare As VbCompareMethod = vbBinaryCompare])
string Required. String expression containing substrings and delimiters. If expression is a zero-length string(""), Split returns an empty array, that is, an array with no elements and no data..
[Delimiter] Optional. String character used to identify substring limits. If omitted, the space character (" ") is assumed to be the delimiter. If delimiter is a zero-length string, a single-element array containing the entire expression string is returned..
[Limit] Optional. Number of substrings to be returned; –1 indicates that all substrings are returned..
[Compare] Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. See Settings section for values..
In this example we will work with is "Alex,Jon,Rick".
The result is "Alex" "Jon" "Rick".
This will keep any spaces surrounding the names, so you could use the Trim function to get rid of these.
The Settings are:
Compare
Constant
Value
Description
vbUseCompareOption
-1
Performs a comparison using the setting of the Option Compare statement.
vbBinaryCompare
0
Performs a binary comparison.
vbTextCompare
1
Performs a textual comparison.
vbDatabaseCompare
2
Performs a comparison based on information in your database. (Microsoft Office Access 2007 only.)
FORM
In a Form you could set the Default Value of a Textbox to
=Split("Alex,Jon,Rick", ",")
VBA
In a Form add a TEXTBOX control and rename it "txtSplit", then you could add the following in the Load Event.
Private Sub Form_Load()
txtSplit = Split("Alex,Jon,Rick", ",")
End Sub
Course
Want to learn more? Request this via the contact form.
Search
You can find more about this by searching the website.