Delete Entire Rows and Columns

Delete Rows and Columns using Excel Visual Basic

Deleting Rows using VBA

The basic format:

Rows([Row Number]).EntireRow.Delete

Substitute “[Row Number]” with the row number you want to remove. This moves all rows up. So if you chose to remove row 15, row 16 would become the new row 15, 17 would move up to 16 and on down the line of rows.

Example:

We want to remove the orange row:

RowDelStart

That is row 15, our code may look like this:

Private Sub CommandButton1_Click()
    Rows(15).EntireRow.Delete
End Sub

When executed, the sheet now looks like this:

RowDelEnd

 

Deleting Columns Using VBA

The basic format:

Columns([Column Number]).EntireColumn.Delete

Substitute “[Column Number]” with the column you wish to remove. This will move the columns to the right of the deleted area over. If you remove column “O” then column “P” will become the new “O” column, “Q” will become “P” and on down through the entire sheet.

We want to remove the orange column:

ColDelStart.png

Private Sub CommandButton1_Click()
    Columns(15).EntireColumn.Delete
End Sub

OR

Private Sub CommandButton1_Click()
    Columns("O").EntireColumn.Delete
End Sub

When the above code is executed, it will look like this:

ColDelEnd.png

 

Excel VBA Resources

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.