Macro must run multiple times before completion
Your problem is when you move down the worksheet and delete a row you are
skipping a row. When ever you have two consecutive row that need to be
deleted the 2nd is being skipped. You have to move up the worksheet.
Sub Delete()
Dim myRange As Range
Dim iLastRow As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For RowCount = LastRow To 1 Step -1
With Range("G" & RowCount)
If .Value = "FUNDED" Or .Value = "DOCS-OUT" Or .Value = "PURCHASED" Then
Rows(RowCount).Delete
End If
End With
Next RowCount
End Sub
"TMc21" wrote:
I am trying to run a macro that will delete row if a certain keyword is
spotted, but I have to run the macro multiple times before it cleans out the
spreadsheet completley. Below is what I have.
Sub Delete()
Dim myRange As Range
Dim iLastRow As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Set myRange = Range("G2:G" & LastRow)
For Each c In myRange
c.Select
If c.Value = "FUNDED" Or c.Value = "DOCS-OUT" Or c.Value = "PURCHASED" Then
ActiveCell.EntireRow.Select
Selection.Delete
End If
Next
End Sub
|