Chapter 1 1 • Manipulating Strings
want converted, and its output will be the converted string. The following example
places the word “HELLO” into strOut:
strOut = UCase("hello")
This chapter presents three ways to convert text to upper- or lowercase: the UCase/
LCase functions, the > and < characters in the Format function, and the
vbUpperCase and vbLowerCase constants with the StrConv function. Use the technique
that’s most comfortable for you.
Because using the Format function can be overkill in some circumstances, VBA
also supplies simpler, special-case functions for situations when you simply need
to format a date, a number, or a percent.
FormatCurrency, FormatNumber, FormatPercent
The FormatCurrency, FormatNumber, and FormatPercent functions each accept a
numeric expression and optional parameters that specify how you want the out-
put value to be formatted. The obvious differences between the functions are that
the FormatCurrency function formats its output as currency, while the other two
functions simply format their output as a numeric value. FormatPercent also mul-
tiplies its result by 100 and tacks on a percent (%) sign. However, no matter what
choices you make, the output value from all of these functions is always a string.
Table 1.5 lists the parameters for the FormatCurrency, FormatNumber, and For-
matPercent functions. (All display options other than those shown in Table 1.5 are
controlled by the Windows regional settings.) These parameters make it simple to
format currency, numeric, and percent values.
Several of these functions include parameters that would appear to be Boolean
values (True or False) but, in fact, support three values: True, False, or Use Default.
That is, you can set these options to be either True or False specifically, or you can
use the default value specified in the Windows regional settings. To make it easier
for you to specify which of these three values you’d like to use, VBA provides an
enumerated type, vbTriState. All functions that can accept one of these three
values allow you to choose from the constants vbTrue (–1), vbFalse (0), or