I am new to Excel VBA and could really use some help. I tried searching for a solution throughout the web but was unable to find a similar problem.
I am trying to create a macro that will help to delete Rows based on certain criteria and continue deleting rows until another certain criterion is met.
So for example. In the table below, I would like to delete Rows where Col A = 1 AND Col C = 0, and then continue deleting the rows below that row UNTIL Col A = 1 and Col C <> 0
A | B | C
-----|-----|-----
1 | TC | 2
-----|-----|-----
2 | TC | 1
-----|-----|-----
1 | TC | 0
-----|-----|-----
2 | TC | 2
-----|-----|-----
3 | TC | 1
-----|-----|-----
1 | TC | 2
-----|-----|-----
1 | TC | 0
-----|-----|-----
1 | TC | 1
-----|-----|-----
2 | TC | 0
-----|-----|-----
3 | TC | 2
So the end result of the macro would be:
A | B | C
-----|-----|-----
1 | TC | 2
-----|-----|-----
2 | TC | 1
-----|-----|-----
1 | TC | 2
-----|-----|-----
1 | TC | 1
-----|-----|-----
2 | TC | 0
-----|-----|-----
3 | TC | 2
Ideally, I would like to Loop this again with Deleting Rows where Col A = 2 and Col C = 0 and deleting the rows below that row until Col A = 2 and Col C <> 0.
Below is the macro that I Came up with. Open to all suggestions and eager to learn.
Sub deleterow()
Range("C2").Select
Do Until ActiveCell.Offset(0, -2) = "1" And ActiveCell.Value <> "0"
If ActiveCell.Value = "0" And ActiveCell.Offset(0, -2) = "1" Then
Rows(ActiveCell.Row & ":" & Rows.Count).Delete
End If
Loop
End Sub
Looking forward to hearing back!
Thank you