Tuesday, September 22, 2015

Range and Resize

We have learned how to use Offset method in the previous section. In this section, we learn how to use Resize method. Resize method enables us to resize the range of selected cells. For example, if we write the code as follows:

Sub TestSub

Range("A1").Resize(2,2).Select

End Sub

This macro selects the cells A1 to B2. Note that (2,2) cell is B2, which is equal to the parameter of Resize method.

Sub TestSub()

Range("A1").Resize(3, 2).Select

End Sub

This selects the cells A1 to B3. As we see above, when the property of the Range object is A1, Resize method with the parameter (3,2) (which is equal to B3) makes a selecting range A1 to B3.

Note that, if we write similar thing with the Offset method,

Sub TestSub

Range("A1").Offset(3,2).Select

End Sub

This would selects the cell C3. Offset method just moves a selecting cell or range to a new location, while Resize method makes a new range.