Info

Press F8 four more times to run through the line of code with Cells.Select. Again, position the cursor in the Immediate window just after Print Selection.Address and press Enter. The query is run again, and the most recent address is shown with the prior answers moved down in the Immediate window (see Figure 2.31).

Figure 2.31

After selecting all cells with Cells.Select, place the cursor after the query in the Immediate window and press Enter. The new answer is that the selected range is all rows from 1 to 65536.

<>

Rous("14:14"J.Select Selection.Font.Bold - True Cells.Select

Selection.Columns.AutoFit End Sub

zS

= <i i

m me díate

Print Selection.Address 51:S6553 6 |Sl: $1

$E$14:$G$14

You can also use this method to change the query. Click to the right of the word .Address in the Immediate window. Use the backspace to erase the word Address and instead type Rows.Count. Hit Enter and the Immediate window tells you the number of rows in the Selection (see Figure 2.32).

Figure 2.32

Delete part of a query, type something new, and press Enter.The previous answers are pushed down and the current answer is displayed.

Figure 2.32

Delete part of a query, type something new, and press Enter.The previous answers are pushed down and the current answer is displayed.

This technique is excellent when you are trying to figure out a sticky bit of code. I may find myself querying the name of the active sheet (Print Activesheet.Name), the selection (Print Selection.Address), the active cell (Print ActiveCell.Address), the formula (Print ActiveCell.Formula) in the active cell, the value of the active cell (Print ActiveCell.Value or—Print ActiveCell because .Value is the default property of a cell), and so on.

To dismiss the Immediate window, use the X in the upper-right corner of the Immediate window. (Ctrl+G does not toggle the window on and off.)

Querying by Hovering

In many instances, you can hover your mouse over an expression in the code. Wait a second, and a tooltip pops up showing you the current value of the expression. This is invaluable for you to understand when you get to looping in Chapter 5, "Looping." And it still will come in handy with recorded code. Note that the expression that you hover over does not have to be in the line of code just executed. In Figure 2.33, Visual Basic just selected Row 1 (making A1 the ActiveCell). If I hover the mouse over ActiveCell.Formula, I get a tool tip showing me that the formula in the ActiveCell is the word InvoiceDate.

Figure 2.33

Hover the mouse cursor over any expression for a few seconds and a tooltip shows the current value of the expres-

Figure 2.33

Hover the mouse cursor over any expression for a few seconds and a tooltip shows the current value of the expres-

0 0

Post a comment