By Hemanta Sundaray on 2021-09-01
A VBA method performs an action.
We use the Select method to select a range of cells. The following statement selects a range in the active worksheet.
Range("A1:C6").Select
The following procedure copies the range A1:A4 and pastes it into a new range beginning at cell B1.
Sub CopyRange()
Range("A1:A4").Copy Range("B1")
End Sub
In the code example above, the argument (Range("B1")) that we pass to the Copy method corresponds to the destination range for the copy operation.
The Clear method deletes all the contents of a range, as well as all the cell formatting. The following statement clears both the contents and the formatting in column B.
Columns("B:B").Clear
There are two related methods: ClearContents & ClearFormats. The ClearContents method deletes the contents of the range but leaves the formatting intact. Conversely, the ClearFormats method deletes the formatting but leaves the contents of the range intact.
The following statement deletes row 5.
Rows("5:5").Delete
When we delete a range, Excel shifts the remaining cells around to fill up the range we deleted.