Ranges of Inactive Worksheets

As with the Range property, you can apply the Cells property to a worksheet that is not currently active:


If you want to refer to a block of cells on an inactive worksheet using the Cells property, the same precautions apply as with the Range property. You must make sure you qualify the Cells property fully. If Sheet2 is active, and you want to refer to the range A1:E10 on Sheet1, the following code will fail because Cells(1,1) and Cells(10,5) are properties of the active worksheet:

Sheets("Sheet1").Range(Cells(1,1), Cells(10,5)).Font.Bold = True

A With...End With construct is an efficient way to incorporate the correct sheet reference:

With Sheets("Sheet1")

.Range(.Cells(1, 1),

.Cells(10, 5):

1.Font.Bold = True

End With

0 0

Post a comment