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

preview_player
Показать описание
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 data-set, 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.

Need help opening the VBA editor?

Code:
Sub delete_zeros()

Dim count As Long
Dim i As Long

'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

Loop

End Sub

#ExcelVBA #ExcelMacro
Рекомендации по теме
Комментарии
Автор

thanks for your help! it worked for me! even if the solution does not seem to be the cleanest it is the most effective one for my problem so far.

antonimaraton
Автор

Happy new year dude!!! Wishing you best if luck!!! 🥳💯

CollDott
Автор

Thank you for the help! You saved my semester!!!

barackoredskins
Автор

This works like a charm! Thanks, man!

darikae
Автор

Really nice, compact and well explained. THANKS!!!

noey
Автор

Finally a simple way to delete blank rows... been looking for days

brunomaia
Автор

by far the best explained tutorial. you helped me greatly!

bedhed
Автор

Thanks for a great video, you explained it really well and in such a short time too :)

officeprovement
Автор

Worked great for me on a 20, 000 row monster GTF RNA sequencing reference genome file after I deleted the i=i-1. I think my loop got stuck if that remained in there. But, I had no sequential conditional deletions since the file staggers everything I needed to delete in the first row of any 4. Thanks for the help Gregg.

andriyfedoriouk
Автор

Incredible video, thanks so much

I'm not a coder but I feel like it's an easy fix.
If I require columns (for instance) C, E and G (so not just i, 7; but i, 3 and i, 5 as well) to run the same code (but I do not want to go through the effort of changing it from i, 3 to i, 5 etc etc in the module for each sheet), how best could I do this?

Thank you!

Pavsta
Автор

Man thank you so much! I'm stuck with this issue for an hour, couldn't imagine it would be so difficult! There is no solution in portuguese channels or site. Greetings from Brazil!

viscarinc
Автор

Hello, this video is really helpful.
I was wondering if there a way to add multiple conditions.

Eg. delete all the rows with "0", "1" and "5".
Thank you.

finni
Автор

Thanks for this. If there are formulas on the sheet even on the zero columns, does this affect the final output leaving #REF errors?

stanleymarketing
Автор

Actualy i make it by "for i " method but when delete row, the next row is take old row position so i can't delete row in one click but i get solution by your vedio thanks a lots

sandipmakwana
Автор

Thank you for the video. By any chance do you know how to use excel VBA to delete all cells from row 5 till the last row?

selvan
Автор

Thanks! How do you have this code run through all the sheets?

sammy
Автор

Would u like to make video on VBA for find a specific word and delete the entire column.

Ravikumar.ujjusharma
Автор

excellent video! Thanks you saved me a lot of time :D

SebiScoot
Автор

VERY GOOD i attached the Macro to a button works OK. That's tedious having to press a button each time to remove the zero's in a column. Is there a way that when a zero is entered into a cell that the row is deleted automatically

andrewmatthews
Автор

i have deleted my table by your code
how can i return it
please reply me as soon as posible

sarsinkManaging