Christopher Greaves

Contact Me

ON LINE STORE

ON LINE STORE

ON LINE STORE

ON LINE STORE

Building and Maintaining Excel Libraries

If you are interested in applications please visit www.VBASolutions.ca .

If you are interested in end-user macros please visit www.TorontoMacros.com .

strSplitAt

This function takes two string arguments and returns the leading portion of the first string.

A character string looks like this:

"Christopher Paul Reynolds Greaves"

If we want to split the names off one by one, we need to recognize that the names are delimited by the space character.

We could obtain the first name by using strSplitAt:

strSplitAt ("Christopher Paul Reynolds Greaves"," ")

In practice, we like to use strings which carry their own delimiter as the leading string. In this manner we never need to declare our delimiter in advance; we can switch from using space, comma, tab, or whatever, just be making the delimiter the first character of the string.

It’s easier to build the string that way, too!

Sub TESTstrSplitAt()

MsgBox UW.strSplitAt("Christopher,Paul,Reynolds,Greaves", ",")

Dim strInputString As String

strInputString = ",Christopher,Paul,Reynolds,Greaves"

Dim strDelimiter As String

strDelimiter = Left(strInputString, 1)

While Len(strInputString) > 0

MsgBox UW.strSplitAt(strInputString, strDelimiter)

Wend

End Sub

Contact Me