Moving Copying and Deleting Ceils

In the process of developing a new worksheet model, you often find yourself moving and copying cells and deleting cell contents. Visual Basic allows you to automate these worksheet editing tasks with simple-to-use methods: Cut, Copy, and Clear.

To render this into VBA: Enter this in the Immediate window:

Move the contents of cell A5 to cell A4. Range("A5").Cut

Destination:=Range("A4")

Copy a formula from cell A3 to cells Range("A3").Copy

D5:F5. Destination:=Range("D5:F5")

Delete contents of cell A4. Range("A4").Clear _Range("A4").Cut_

Notice that both the Cut and Copy methods used with the Range object require a special argument called Destination. This argument specifies the address of a cell or a range of cells where you want to place the cut or copied data. In the last example, the Cut method is used without the Destination argument to remove data from the specified cell.

The Clear method deletes everything from the specified cell or range, including any applied formats and cell comments. If you want to be specific about what you want to delete, use the following methods:

■ ClearContents—clears only data from a cell or range of cells

■ ClearFormats—clears only applied formats

■ ClearComments—clears all cell comments from the specified range

0 0

Post a comment