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:
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:
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:
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: