Moving a range

You move a range by cutting it to the Clipboard and then pasting it in another area. If you record your actions while performing a move operation, the macro recorder generates code like the following:

Sub MoveRange()





End Sub

As with the copying example earlier in this chapter, this is

not the most effi-

cient way to move a range of cells. In fact, you can move a

range with a single

VBA statement, as follows:

Sub MoveRange2()

Range("A1:C6").Cut Range("A10")

End Sub

This macro takes advantage of the fact that the Cut method can use an argument that specifies the destination. Notice also that the range was not selected. The cell pointer remains in its original position.

Was this article helpful?

0 0

Post a comment