How to get free YouTube subscribers, likes and views?
Get Free YouTube Subscribers, Views and Likes

Excel VBA Macro: Delete Rows Based on Cell Value (Zeros and Blanks)

Follow
greggowaffles

Excel VBA Macro: Delete Rows Based on Cell Value (Zeros and Blanks). We create a macro that deletes rows based on cell value with specific text. If you ever need to remove all rows that contain a specific value in an excel worksheet, you can use this code to remove those rows.

In this example, we delete rows that contain zeros and delete blank rows specifically. The code searches for a specific value in a designated column, then deletes that entire row if it contains the value you want deleted. The macro counts the number of total rows in the dataset, then goes down each row searching for the specific value in order to delete the entire row, until it reaches the bottom of the range.

Subscribe:    / @greggowaffles  

Need help opening the VBA editor?
   • Excel VBA Macro: How To Create A Macr...  

Code:
Sub delete_zeros()

Dim count As Long
Dim i As Long

count = ActiveSheet.Cells(Rows.count, "A").End(xlUp).Row
'msgbox count

i = 1

Do While i = count

If Cells(i, 7) = 0 Then

Rows(i).EntireRow.Delete
i = i 1

End If

i = i + 1
count = ActiveSheet.Cells(Rows.count, "A").End(xlUp).Row

Loop

End Sub


#ExcelVBA #ExcelMacro

posted by valeriaangz