VBA Flashcards
learn VBA (119 cards)
Select all cells in Current region, VBA and keyboard?
Selection.CurrentRegion.Select; Ctrl+Shift+8 (*)
Return the color index to a Message Box
MsgBox Selection.Interior.ColorIndex
How do you force the declaration of variables?
Tools/Options (in VBA). Add tick to “Require Variable Declaration”.
What does Option Explicit do?
Make you declare all variables
What is the scope of a variable
How far it reaches
How is a variable declared locally (within a single procedure)?
By using a Dim or Static statement within the procedure.
How is a variable declared within the current module?
By using a Dim statement before the first Sub or function.
What does a Public statement do?
Declares a variable in all Subs and Functions in all modules in the current workbook
What does Static do when used in place of Dim?
Freezes the variable
What is the shortcut for Step Over in debugging?
Shift + F8
Shortcut for Debug run to cursor (runs up until the cursor)
Ctrl + F8
How do you add a Watch
Debug menu, Add Watch
How do you step out of a sub procedure
Ctrl + Shift + F8
When debugging, how do you add a break point and what does it do?
LHB in left margin. It breaks the sub.
How do you halt your code if debugging when a criteria is satisfied?
Insert “Debug.Assert” with a criteria such as “s < 5”. Or you can use “Debug Menu, Add Watch.. (Break When Value is True)
How do you change from absolute to relative references when recording a Macro?
Developer Tab, Use Relative References
What is counter intuitive about Debug.Assert
Debug.Assert runs until the criteria is FALSE
What should you avoid when using Dim in functions
Redimming of arguments
in functions, why (a as Double, b as Double) As Double
Because we also DIM th output
How do you debug a function?
Break point. In Excel, click into the function, hit Enter. in VBA you can now step through.
Why should you avoid message boxes in cells?
Because answer does not get returned to cell and because if copy to multiple cells, you get as many pop ups!
The order of VBA operators
^, -, *,/ ,\, mod, +/-, string, relational operators, logical operators
What are properties
Attributes of objects
What are methods
actions to be taken on objects