Lynda: Up and Running With VBA In Excel Flashcards

1
Q

What does a programming language need to enable? (four things)?

A
  • Accept Input
  • Store Data
  • Manipulate Data
  • Produce Output
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the three elements of an object in an Object-Oriented Programming Language?

A
  • Properties
  • Methods
  • Events
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are some examples of common objets in Excel VBA?

A
  • Application
  • Workbook
  • Worksheet
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are examples of properties in a workbook object in Excel VBA?

A
  • Name
  • Sheets
  • Saved
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are some examples of methods for a workbook object in Excel VBA?

A
  • Close
  • PrintOut
  • Save
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are some examples of Events for a workbook object in Excel VBA?

A
  • BeforeClose
  • NewSheet
  • BeforeSave
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are some examples of properties for a Worksheet object in Excel VBA?

A
  • Name
  • UsedRange
  • Visible
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are some examples of methods for a Worksheet object in Excel VBA?

A
  • Activate
  • Copy
  • Delete
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are some examples of Events for a Worksheet object in Excel VBA?

A
  • Activate
  • Deactivate
  • Change
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Where can you find a list of all objects and their properties in Excel?

A

In the VBA window, look for the “Object Browser”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you create a new function in VBA? Example (sales Tax)?

A

In the project window enter “function instead of Sub, and then name it your function (all caps to match existing functions), then parentheses to define inputs and outside parentheses to define output

Example:

Function SALESTAX(curSales As Currency, dblRate As Double), As Double

SALESTAX = dblRate * curSales

End Function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why should you make most of your Subroutines “Private”? How?

A

Most “Subs” should be “Private” unless they absolutely need to be accessible from other workbooks, such as a general use conditional subroutine, etc. Otherwise someone might accidentally use the macro on their workbook and cause disastrous results. You can make a “Sub” private by putting “Private” in front of it so it looks like “Private Sub”. This will prevent it from being accessed in other workbooks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you add effective comments to your VBA code?

A

First comment should be your name, and when the code was created

Next should be a description of what the code does, and the workbook name, in case someone copies it elsewhere

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are data types in Excel VBA? Examples? How can you find a list of them all?

A

Data types are categories which limit the options of a variable to save memory and load faster when completing complex operations

Examples: Byte has to be between 0 and 255 and must be an integer. Boolean can only be True or False

Go to “Help” and type “Data type Summary” in the search, then click on the article that comes up

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does “Dim” stand for in VBA? Why is it used?

A

Dim stands for Dimension

It is used at the top of your code to define a variable as a certain data type to save memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does “Option Explicit” do in VBA? Why is it valuable? How is it used?

A

Option Explicit is declared above the “Sub” and will require that all variables are defined at the top of the “Sub”, otherwise it will generate an error. It is valuable to prevent typos in errors throughout the code and the generation of new variables as a result.

17
Q

How do you create a global variable in VBA? Why is this useful?

A

You can create a global variable in excel by defining it in the declarations section above the “Sub”s. This is valuable because it is faster than redeclaring variables over and over in every Sub if they will be the same.

18
Q

How do you define a variable as “Static”? Why is this valuable?

A

Instead of using “Dim” you enter “Static” before the variable. This is useful because the variable will increment across subroutines if a value is added to it, instead of looping to “0”. You cannot make a static global variable.

19
Q

How do you define a variable as a “Constant”? Why is this useful?

A

A “constant” is defined by putting “Const” before a variable, but only in the declarations area above the “Subs”. This allows the variable to stay constant throughout subs. If the value is change locally, it will overwrite the constant, but only in the “Sub” where it’s overwritten.