Listing Using the Range Property to Refer to Groups of Cells

Sub UsingRange()

Dim ws As Worksheet Dim rg As Range

Set ws = ThisWorkbook.Worksheets(l)

' specifying a range using Cells

' this range is equivalent to A1:J10

Set rg = ws.Range(ws.Ce11s(1, 1), ws.Ce11s(10, 10))

' sets the value of each cell in the

Set rg = ws.Range("D4", "E5") rg.Font.Bold = True ws.Range("A1:B2").Horizonta1A1ignment = xlLeft

Set rg = Nothing Set ws = Nothing End Sub

One important thing to notice in Listing 8.3 is that you don't have to assign values cell by cell. You can assign the same value (or formula, if you're using the Formula property) to a group of cells in one fell swoop. Figure 8.2 shows the output produced by the UsingRange procedure.

0 0

Post a comment