A VBA method performs an action. A Range object has dozens of methods, some of which will be covered
here.
Range("A1:C12").SelectBefore selecting a range, make sure you've activated the range's worksheet, otherwise you get an error or the wrong range is selected.
Sheets("Sheet1").Activate Range("A1:C12").SelectThe following statement generates an error. You must use two statement instead of just one: one to activate the sheet and another on to select the range:
Sheets("Sheet1").Range("A1:C12").Select
Sub CopyRange() Range("A1:A12").Select Selection.Copy Range("C1").Select ActiveSheet.Paste End SubActually you don't have to select a range before doing something to it. In fact the following procedure accomplishes the same task as the preceding example
Sub CopyRange2() Range("A1:A12").Copy Range("C1")This procedure takes advantage of the fact that the Copy method can use an argument that corresponds to the destination range for the copy operation.
Columns("D:D").ClearThere are two related methods. The ClearContents method deletes the contents of the range but leaves the formatting intact. The ClearFormats method deletes the formatting in the range but not the cell contents.
Rows("6:6").DeleteWhen you delete a range that is not a complete row or column, Excel needs to know how to shift the cells.
Range(C6:C10").Delete xlToLeftThe Delete method uses an argument to indicate how Excel should shift the remaining cells. Here the built-in constant xlToLeft is used. Another constant is xlUp (for shifting up).