So I have numerous sheets in a workbook and I would like my macro to go through all the sheets in the workbook and delete those rows in each sheet that contains a cell with "PY" in it. Here is what I have and it is not working. What am I doing wrong?
Dim WS As Worksheet
Dim r As Long
Dim c As Long
r = 1
c = 1
For Each WS In ThisWorkbook.Worksheets
For c = 1 To 20
For r = 1 To 200
If Cells(r, c).Value = "PY" Then
Rows(r).Delete
r = r - 1
End If
Next r
Next c
Next WS
Dim WS As Worksheet
Dim r As Long
Dim c As Long
r = 1
c = 1
For Each WS In ThisWorkbook.Worksheets
For c = 1 To 20
For r = 1 To 200
If Cells(r, c).Value = "PY" Then
Rows(r).Delete
r = r - 1
End If
Next r
Next c
Next WS
Last edited: