Return to VBA Code Examples

Delete or Insert Rows Based on Cell Value

This tutorial will demonstrate how to delete or insert rows based on cell values.

Delete Row Based on Cell Value

This will loop through a range, and delete rows if column A says “delete”.

We must start the loop with the bottom row because deleting a row will shift the data, skipping rows if you loop top to bottom.

Also, notice that instead of manually entering in the last row, we calculate the last used row.

Delete Row – Based on Filter

In the previous example, we looped through the rows, deleting each row that meets the criteria. Alternatively, we can use Excel’s AutoFilter to filter rows based on some criteria and then delete the visible rows:

Delete Row Based on Cell Criteria

This will loop through a range, deleting rows if the cell in column A meets certain criteria (< 0):

Delete Row if Cell is Blank

This will loop through a range, deleting a row if a cell in column A is blank:

Delete Blank Row

Alternatively, if you want to delete a row if the entire row is blank (Click link for a slightly different method), you can use this code:

Delete Row if Cell Contains Value

This will loop through a range, deleting a row if the cell in column A is not blank:

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! automacro

Learn More!!

Insert Row Based on Cell Value

This will loop through a range, inserting rows if a certain cell in that row says “insert”: