Excel VBA Test
Excel VBA Test
Excel VBA Test
Running A macro......................................................................................................................................................16
Deleting a Macro......................................................................................................................................................28
Properties ................................................................................................................................................................34
Methods ..................................................................................................................................................................36
COLLECTIONS ...........................................................................................................................................................36
Constants .................................................................................................................................................................46
worksheets ..............................................................................................................................................................50
Specialcells...............................................................................................................................................................52
And ..........................................................................................................................................................................56
or .............................................................................................................................................................................57
Not ..........................................................................................................................................................................58
INTELIGENES TECHNOLOGIES|ALL CONTENT RESERVED|COPYRIGHT
P A G E |2
RESERVED
CHOOSING BETWEEN THIS OR THAT ........................................................................................................................58
if…Then…Else ...........................................................................................................................................................60
IF…THEN…ELSEIF ......................................................................................................................................................61
SELECT CASE.............................................................................................................................................................61
WHAT is A loop?.......................................................................................................................................................66
for…next ..................................................................................................................................................................68
FOR…EACH…NEXT ....................................................................................................................................................69
DO…WHILE ..............................................................................................................................................................71
DO…UNTIL ...............................................................................................................................................................71
DO…LOOP…WHILE ...................................................................................................................................................73
DO…LOOP…UNTIL ....................................................................................................................................................73
While…Wend ...........................................................................................................................................................73
WHAT is An ArrAy?...................................................................................................................................................75
CHAPTER11 ..................................................................................................................................................................83
CHAPTER12 ..................................................................................................................................................................91
COMMANDBUTTONS .............................................................................................................................................102
CREATING A USERFORM.........................................................................................................................................137
SHOWING A USERFORM.........................................................................................................................................143
Hiding A Userform..................................................................................................................................................145
labels .....................................................................................................................................................................148
TEXTBOXES ............................................................................................................................................................150
LISTBOXES ..............................................................................................................................................................152
COMBOBOXES........................................................................................................................................................153
CHECKBOXES..........................................................................................................................................................155
OPTIONBUTTONS ...................................................................................................................................................157
FRAMES .................................................................................................................................................................159
INTELIGENES TECHNOLOGIES|ALL CONTENT RESERVED|COPYRIGHT
P A G E |5
RESERVED
CHAPTER20 ADVANCED USERFORMS ....................................................................................................................162
The Code window is where the code for macros and VBA procedures is located. The VBE provides separate code
windows for each module. A good way to think of this is, for every object (worksheet, module, and so on) you see
listed in the Project Explorer, the VBE has provided a code window. You will note that the drop-down in the upper
right-hand corner of Figure 3-3 displays the name of the macro that is currently showing in the Code window
(mySort). As you create multiple macros, you can use this drop-down to quickly move from one macro to another.
Understanding modules
➪ ➪
➪ ➪
➪ ➪
➤➤
➤➤
➤➤
➤➤
➤➤
As you look at the MsgBox line, note that the message box arguments are contained within parentheses. A
message box has two mandatory arguments: the prompt, which is the text you place in the body of the message
box, and the button configuration. Other combinations of buttons include OKCancel, YesNoCancel, and
AbortRetryIgnore. The title of the message box is optional, but I always enter it to offer a more customized
experience for the user.
➤➤
Range(Application.Caller.Address).Interior.ColorIndex ‘Loop through each cell in the range. For Each ColorCell In
RangeToSum ‘If the cell’s color matches the color we are looking for, ‘keep a running subtotal by adding the cell’s
number value ‘to the mySum variable. If ColorCell.Interior.ColorIndex = ColorID Then mySum = mySum +
ColorCell.Value Next ColorCell ‘The cells have all been evaluated, so you can define the SumColor function ‘by setting it
equal to the mySum variable. SumColor = mySum End Function
Code cursor
will
be
blinki
ng in
the
large
white INTELIGENES TECHNOLOGIES|ALL CONTENT RESERVED|COPYRIGHT
P A G E | 119
pane RESERVED
on the
right,
which
is the
new
INTELIGENES TECHNOLOGIES|ALL CONTENT RESERVED|COPYRIGHT
P A G E | 120
RESERVED
INTELIGENES TECHNOLOGIES|ALL CONTENT RESERVED|COPYRIGHT
P A G E | 121
RESERVED
➪ ➪
➪ ➪
➤➤
➤➤ ➤➤
➤➤ ➤➤
➤➤ ➤➤