Page 156 - Excel Progamming Weekend Crash Course
P. 156
h540629 ch10.qxd 9/2/03 9:34 AM Page 131
Session 10 — Using Ranges and Selections 131
Element (1,1) contains the value 1.
Element (2,1) contains the value 2.
Element (4,2) contains the value 8.
Figure 10-5 A multiple cell range used in the example in the text
The program that is presented in Listing 10-3 demonstrates how to read data from single-
and multiple-cell ranges. The program reads data from the current selection and displays it
in the immediate window using the Debug.Print statement. To try this program:
1. Place the code from the listing into a module in the VBA Editor.
2. Switch to Excel, and select a range that contains data. It can be a single cell range
or a multiple cell range.
3. Run the program.
Listing 10-3 Reading values from single and multiple cell ranges
Public Sub DisplayRangeData()
Dim r1 As Range
Dim i As Integer, j As Integer
Dim x As Variant
Set r1 = Selection
Continued