If a row has the value INACTIVE in column D and #N/A in column H, I want to delete that row.
I tried to achive that with my code below, but no row actually gets deleted.
Dim ws3 As Worksheet
Dim r As Integer
Set ws3 = ThisWorkbook.Sheets("Sheet2")
With ws3
For r = Sheet2.UsedRange.Rows.Count To 2 Step -1
If Cells(r, "D").Value = "INACTIVE" And Cells(r, "H").Value = "#N/A" Then
Sheet2.Rows(r).EntireRow.Delete
End If
Next
End With
AutoFilterto get your rows and then delete themIfis checking the value of cells in the ActiveSheet, not in Sheet2. Maybe it should be something likeIf Sheet2.Cells(r, "D").ValueorIf ws3.Cells(r, "D").Valuebecause you are mixing things here.ws3isSheet2or is itSheets("Sheet2")? isSheet2=Sheets("Sheet2")your code is totally confusing.