Other Debug facilities

The Debug.Print statement displays the values of variables, or cells, as they change during execution. The Immediate window is used to display output from Debug.Print. To see how this w orks, suppose w e w anted to display the contents of each cell during the running of the validateWeekSales macro. We could do this by adding these lines during the loop execution:

Debug.Print "The Cell Value is =", cell.Value

Figure 8.9 shows how this statement has b een added to the validate WeekSales procedure. Notice that the statement has been inserted below the start of the For...Next loop. The results are displayed in the Immediate window.

Microsoft Visual Basic - SALESMAN.hIs - [othersalesmanmacros (Code)]

File Edit View Insert Format Debug Run Tools Add-Ins Window Help

I izi - 0 Í Sto g tt | «i ©i ► nafa? írf s£" ^ ©

f valiilateWeek Sales

Worksheets("Ueeklysales").Select ActiveSheet.Unprotect Dim cell As Object

For Each cell In Range ("IiJeek_sales")

Debug.Print "The cell value is =", cell.Value

If Not IsWumeric(cell) Then i 1_I

Worksheets("Ueeklysales").Select ActiveSheet.Unprotect Dim cell As Object

For Each cell In Range ("IiJeek_sales")

Debug.Print "The cell value is =", cell.Value

If Not IsWumeric(cell) Then i 1_I

[mmediat?

E3|

r

The

cell

value

is

=

¿1

The

cell

value

is

=

5

ü:

The

cell

value

is

=

6

The

cell

value

is

=

12

The

cell

value

is

=

32

The

cell

value

is

=

HI

Output from Debug.Print

The

cell

value

is

=

28

The

cell

value

is

=

33

The

cell

value

is

=

23

The

cell

value

is

=

33

The

cell

value

is

=

150

The

cell

value

is

=

166

The

cell

value

is

=

32

The

cell

value

is

77

zi

__

m i jj i

Figure 8.9 Using the Debug.Print statement

Figure 8.9 Using the Debug.Print statement

0 0

Post a comment