In Search of Help

When you use the macro recorder, all your actions are translated into VBA instructions and placed in a module. When studying the recorded procedure, don't forget that help is within your reach. While the meaning of some of the instructions may be pretty straightforward, you will probably find some of them less obvious. This is the time to ask for help. When you're working alone, your VBA tutor is just a click or keypress away. Using Visual Basic online help is quick and easier to use than a paper dictionary or reference manual. If you hate thumbing through the pages of a dictionary to find the needed term, you'll be amazed at how quick you can get to the necessary help page from the Visual Basic Code window.

Let's examine how, with the help of the built-in VBA tutor, you can make the first instruction in the WhatsInACell procedure a part of your VBA vocabulary:

Selection.SpecialCells(xlCellTypeConstants, 2).Select

The above instruction can be broken into three parts. What parts? Is Selection an object or a property? What is SpecialCells? What is Select? To answer these questions, perform the following:

1. Activate the Code window with a procedure you want to analyze.

2. Click anywhere within the word that you don't understand.

The help system opens on the correct page. If your cursor is located within the word Selection, you already know that Selection can be a property of an Application or a Window object. If you position the cursor within the next unknown term (SpecialCells) and again follow the steps above, you end up on the SpecialCells help screen (Figure 2-10).

Notice that each help screen contains lots of information. The type of instruction being looked up is shown at the top of the help window. The type of instruction allows the word to be classified. For example, SpecialCells is a method. The names of objects to which this method can apply are listed under the heading Applies To. The See Also and Example headings below the name of the instruction allow you to quickly jump to other instructions with similar usage or meaning and view a code example that uses this instruction.

The meaning of the instruction is shown below the See Also and Example headings. Next comes the syntax with the required arguments and other parameters. The Remarks section gives situations where using this particular instruction is recommended over using another instruction.

You can easily copy the code in the Example window into your own procedure. Simply highlight the lines you want to copy and press Ctrl+C, or right-click the selection and choose Copy from the shortcut menu. Switch to the Visual Basic Code window, click in the location where you want to paste the code example, and press Ctrl+V or choose Edit | Paste.

Microsoft Visual Basic Help i .

□ M o «=r> H #

SpecialCelts Method


See rese Applies To Example

Returns a Range object that represents all the cells that match the specified type and value- Range object.

expresswn. SpecialCellsf, Type. Value)

expression Required. An expression that returns one of the objects In the Applies To list.

Type Required XICellType. The cells to Include.

Value Optional Variant. If Type Is either HlCellTypeConstants or xltellTypeFormulas, this argument is used to determine which types of eels to include in the result, These values can be added together to return more than one type. The defaiifc is to select all constants or formulas, no matter what the type. Can be one of the following XfcpecialCellsVakie constants:


This example selects the last eel in the used range of Sheet!.

Wo r kshe e ts (w Shee 11"} - Act ivafc e


Objects, properties, and methods of Visual Basic for Applications are explained in detail in the online help.

0 0

Post a comment