VBA (Excel) - Delete a row
Solved
XRay
-
dlescot Posted messages 1 Status Member -
dlescot Posted messages 1 Status Member -
Hello!
I would like to know how to search for a value in a column and delete the corresponding row...
Here is what I did:
Actually, I can't select the entire row to delete it...
Does anyone have a solution?... Thank you in advance! ;o)
I would like to know how to search for a value in a column and delete the corresponding row...
Here is what I did:
Range("A1").Select Do While ActiveCell <> "toto" ActiveCell.Offset(1, 0).Select Loop Selection.Delete Shift:=xlUp Actually, I can't select the entire row to delete it...
Does anyone have a solution?... Thank you in advance! ;o)
14 answers
-
And simply a
Selection.EntireRow.Delete
Wouldn't that be easier?
Or a bit more complicated, but simpler than what was proposed:Rows(Selection.Row).Delete shift:=xlUp
But I see at least two problems with your code:- If "toto" appears twice, it will only be deleted once
- If "toto" never appears, you will get an error on the offset at line 65536.
Not knowing how many rows you have, you could use the following code:For i = Cells(1, 1).CurrentRegion.Rows.Count To 1 Step -1 If Cells(i, 1).Value = "toto" Then Cells(i, 1).EntireRow.Delete Next
knowing that you can replace Cells(1, 1).CurrentRegion.Rows.Count with the corresponding number of rows.