Excel 2019 Bible

(singke) #1

Chapter 42: Introducing Visual Basic for Applications


42


other VBA procedures or used in worksheet formulas, just as you would use Excel’s built-in
worksheet functions.

Figure 42.6 shows a custom worksheet function. This function is named CubeRoot, and it
requires a single argument. CubeRoot calculates the cube root of its argument and returns
the result. A Function procedure looks much like a Sub procedure. Notice, however, that
function procedures begin with the keyword Function and end with an End Function
statement.

FIGURE 42.6
This VBA function returns the cube root of its argument.

A workbook that contains this function is available on this book’s website at http://www.wiley.com/go/
excel2019bible. The file is named cube root.xlsm.

Creating VBA functions that you use in worksheet formulas can simplify your formulas and enable you to
perform calculations that otherwise may be impossible. Chapter 43, “Creating Custom Worksheet
Functions,” discusses VBA functions in greater detail.

Some Definitions


If you’re new to VBA, you may be overwhelmed by the terminology. Here are some key definitions to
help you keep the terms straight. These terms cover VBA and UserForms (custom dialog boxes)—two
important elements that are used to customize Excel:


Code VBA instructions that are stored in a module when you record a macro or enter them manually.


Controls Objects on a UserForm (or in a worksheet) that are used to interact with the user. Examples
include buttons, check boxes, and list boxes.


Function One of two types of VBA macros that you can create. (The other is a Sub procedure.) A function
returns a single value. You can use VBA functions in other VBA macros or in your worksheets.


Continues
Free download pdf