• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

Delete rows based on condition

I need help please with VBA to delete rows on Sheet19 where Column E = "1".  Thanks in Advance.  I have looked for code but nothing seems to help.
0
leezac
Asked:
leezac
1 Solution
 
MichaelBusiness AnalystCommented:
Hi leezac,
this code should do it. It looks in column E for the last used row and then goes upward and deletes a row whenever cell E of that row is "1".

First, try it on a copy of your workbook, as you can't undo it.

sub DelRows()
Dim Lst     As Long
Dim n       As Long

With Sheets("Sheet19")
Lst = .Range("E" & .Rows.Count).End(xlUp).row
For n = Lst To 2 Step -1
    With .Range("E" & n)
        If .Value = 1 Then
            .EntireRow.Delete
        End If
     End With
Next n
End With
End Sub

Open in new window

0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now