Delete Rows and Columns in Excel by VBA code

In this article we are going to explain how you can delete rows or columns in excel sheet by using VBA code. Delete method helps us to delete rows or columns. You can delete single row/column or multiple rows/columns.

Delete Single Row

At given Position – We use Delete method of Rows or Range object to delete row at a specific position.  Suppose that specific position is 6, you can use any of the following VBA commands to delete row at 6 index.

Rows(6).Delete

or

Range("A6").EntireRow.Delete

or

Range("6:6").Delete

At Active Cell Position – If you want to delete the row of active cell, use the below given VBA command. It will delete entire row of the active cell.

ActiveCell.EntireRow.Delete

Delete Single Column

At given Position – To delete column at a specific position, we use Delete method of Rows or Range object.  Suppose that specific position is 3 (or C position), you can use any of the following VBA code to delete column at C position i.e. column number 3

Columns(3).Delete

or

Range("C3").EntireColumn.Delete

or

Range("C:C").Delete

At Active Cell Position – If you want to delete a column on basis of active cell, use the below given VBA code. It will delete entire column of the active cell.

ActiveCell.EntireColumn.Delete

Delete Multiple Rows

If you want to delete multiple rows (suppose row index 6 to 8), you can use any of below given VBA commands.

VBA delete multiple rows
Range("6:8").Delete

or

Rows("6:8").Delete

or

Range("A6:A8").EntireRow.Delete

Delete Multiple Columns

If you want to delete multiple columns (suppose column C to column D), you can use any of below given VBA commands.

VBA delete multiple columns
Columns("C:E").Delete

or

Range("C3:E3").EntireColumn.Delete

Leave a Reply

Your email address will not be published.