person holding blue and clear ballpoint pen

How to Delete Row or Column in Excel VBA ?

In this post, you’ll learn how you can delete row or column from your excel spreadsheet programmatically using Excel VBA.

person holding blue and clear ballpoint pen

Delete Entire Row or Column in Excel VBA

To delete an entire row in VBA, use the below code snippet

Code:

Rows(1).Delete

or

Code:

Range("a1").EntireRow.Delete

To delete an entire column in VBA

Code:

Columns(1).Delete
Range("a1").EntireColumn.Delete

Delete Multiple Rows or Columns

To delete multiple rows at once,

Code:

Rows("1:3").Delete

For columns,

Code:

Columns("A:C").Delete

Delete Blank / Empty Rows

To delete blank or empty Rows,

Code:

Sub DeleteRows_EntireRowBlank()

Dim cell As Range

For Each cell In Range("b2:b20")

    If Application.WorksheetFunction.CountA(cell.EntireRow) = 0 Then

        cell.EntireRow.Delete

    End If

Next cell

End Sub

Delete Blank Row

To delete a Blank Row

Range("b3:b20").SpecialCells(xlCellTypeBlanks).EntireRow.Delete

Delete Row Based on Cell Value

To delete row based on cell value,

Code:

Sub DeleteRowswithSpecificValue()

Dim cell As Range

For Each cell In Range("b2:b20")

    If cell.Value = "delete" Then

        cell.EntireRow.Delete

    End If

Next cell

End Sub

Delete Duplicate Rows

To delete all duplicate rows in a range,

Code:

Range("b2:c100").RemoveDuplicates Columns:=2

Delete Table Rows

To delete the rows in a Table by referencing ListObjects,

Code:

ThisWorkbook.Sheets("Sheet1").ListObjects("list1").ListRows(2).Delete

Delete Filtered Rows

To delete only rows that is visible after filtering,

Code:

Range("b3:b20").SpecialCells(xlCellTypeVisible).EntireRow.Delete

Delete Rows in Range

To delete all rows in range,

Code:

Range("a1:a10").EntireRow.Delete

Delete Selected Rows

To delete all selected rows,

Code:

Selection.EntireRow.Delete

Delete Last Row

To delete last row,

Column

Cells(Rows.Count, 2).End(xlUp).EntireRow.Delete

Delete Columns by Number

To delete a column by its number,

Code:

Columns (2).Delete

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this post, you’ll learn how to Find Blank cells in excel so that you can remove or delete the blank cells form...
In this article, you’ll learn what is a Gauge Chart in Microsoft Excel. Also, you will learn how to add...
Microsoft Excel provides a shortcut for the users to move columns in excel using two different ways – using Shift...