Ranges of Inactive Worksheets

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

Worksheets("Sheet1").Cells(2,3)

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

Was this article helpful?

0 0
The Accidental Blogging Millionaires

The Accidental Blogging Millionaires

Get Inspired By The Most Popular Bloggers Online! If You Want To Skyrocket Your Success With Business And Improve Your Overall Life You Need To Have A Look At The Accidental Blogging Millionaires! Business can be a fight, particularly when you’re trying to establish one online and like all fights, to succeed you must find the winning techniques and apply them.

Get My Free Ebook


Post a comment