Page 144 - Excel Progamming Weekend Crash Course
P. 144
h540629 ch09.qxd 9/2/03 9:34 AM Page 119
Session 9 — Working with Text 119
Table 9-5 shows some examples of using the Mid statement. The original value of s is
“123456789” in all examples.
Table 9-5 Mid Statement Examples
Statement Result
Mid(s, 4) = “abcd” s contains “1234abcd9”
Mid(s, 4, 2) = “abcd” s contains “1234ab789”
Mid(s, 8) = “abcd” s contains “1234567ab”
Other String Functions
Table 9-6 describes VBA’s remaining string manipulation functions.
Table 9-6 Additional String Manipulation Functions
Syntax Description Example
Len(str) Returns the length (number Len(“hello”) returns 5
of characters) of a string
LTrim(str) Returns a string with any LTrim(“ ABC “) returns “ABC “
leading spaces removed
RTrim(str) Returns a string with any RTrim(“ ABC “) returns “ ABC”
trailing spaces removed
Space(n) Returns a string consisting Space(5) returns “ “
of n spaces
String(n, char) Returns a string consisting String(6, “!”) returns “!!!!!!”
of n copies of the single
character char
Trim(str) Returns a string with both Trim(“ ABC “) returns “ABC”
leading and trailing
removed