I am new to VBA and want to remove rows from an Excel file. I want to remove a row that has a Status 'Completed', but only if there is at least one more row remaining for a CustomerName. In other words, if there is only one more row remaining for a certain CustomerName, it should not be deleted, even though it might have Status 'Completed'.
I figured out how to remove rows if they have Status = 'Completed':
Sub RemoveAlmostAllCompletedRows()
Dim i As Long
i = 1
Do While i <= ThisWorkbook.ActiveSheet.Range("A1").CurrentRegion.Rows.Count
If InStr(1, ThisWorkbook.ActiveSheet.Cells(i, 18).Text, "Completed", vbTextCompare) > 0 Then
ThisWorkbook.ActiveSheet.Cells(i, 1).EntireRow.Delete
Else
i = i + 1
End If
Loop
End Sub
This removes all rows that have 'Completed' in column 18 (Status column). Now I am really stuck finding a way to prevent a row with Status = Completed, if that would delete the last remaining row for a CustomerName.
Any ideas or tips to get me going? Your help is much appreciated!