How to Delete rows in Excel VBA using For loop

preview_player
Показать описание
Title:How to Delete rows in Excel VBA using For loop

Recommended Excel VBA books
===================================================
====================================================

In this video you'll learn how to delete rows using VBA when specific conditions exist and a logic behind it. If you delete the rows from top to bottom then excel will skip the row which presents below the current row so VBA command won't work properly in this case. So you need to go from bottom to top-down approach when you are using For loop. Watch this video to learn more .

Code:

Sub deleterows()
Dim lastrow
'Finding the lastrow in Column A

lastrow = ThisWorkbook.Sheets(1).Range("A65356").End(xlUp).Row
'Deleting the cell contain 1 in Column A
For i = lastrow To 2 Step -1
'Finding the cell which contain 1 in Column A

If ThisWorkbook.Sheets(1).Cells(i, 1) = "1" Then
ThisWorkbook.Sheets(1).Rows(i).EntireRow.Delete
End If

Next i
End Sub

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

Thanks man! You saved my day with that small trick!

familiapipajose
Автор

Thank you this is exactly what I was looking for!

chadlyfromcharlotte
Автор

Mister, I have a question, i have multiple sheets and I want to delete one Row and 3 Columns only, How can I do it? Thanks in advance.

abdulhamidalhaddadi
Автор

how to define this range on inputbox passing value

manishbhandari
Автор

I woud love to see how to add another condition base on the presence of a date formatted cell.

anthonylobello
Автор

How would i delete certain rows / columns? for example delete cells B5-B10 but keep A5-A10. Is this possible? Right now it deletes the row all the way across

LongNguyen-xyip
Автор

I will like to delete row if cell contains vlv in the beginning or vlv at the end of the string. How do I do that?

lourdesgonzalez
Автор

Hi

enjoy your video.
however this video is very blur.
and i need to see the codes.
this codes is exactly what i need for my project.

can you send it to me please.
thanks in advance
Hassen

carpentersfriend
Автор

I have 5 option buttons.
Button1 when clicked shows me - 3 text boxes: Quantity * Unit Price = $ Total.
I want that when clicking on Button2 the text boxes of Button1 be cleared and show me only the values of Button2 and vice versa.

carlosferreira
Автор

i want to delete all the data after a specific row in an excel using vba eg. Deleting all rows in all sheets after a row containing a word "Total Deals"

prathamambre
Автор

if i want to delete the all cell containing everything without specification. How to do?

teuteu