VBA Excel: deleting rows based on value in other sheet

73 Views Asked by At

I am currently trying to clean up my dataset. I currently have two sheets: "sheet1" & "sheet2". The first 11 columns from sheet2 are linked to sheet1, and are therefore identical. However, a 13th column is included in sheet2 which is either "Yes" or "No".

My goal is to make a VBA macro which deletes a specific row in sheet1 when that exact row in sheet2 (column 13), presents "Yes". However, with my current code, only the top (i = 2) rows from sheet2 get deleted.

The thought behind it is that when a row is deleted in sheet1, and sheet2 is linked to sheet1, sheet2 will automatically be deleted.

My current code:

Sub Coentunnel_Delete_rows()
    Dim Acc As Worksheet
    Dim Rev As Worksheet
    Set Acc= Worksheets("Sheet1")
    Set Rev= Worksheets("Sheet2")
    For i = 2 To Acc.UsedRange.Rows.Count
        If Rev.Cells(i, 13).Value = "Yes " Then
            Rows(i).EntireRow.Delete
        End If
        If Rev.Cells(i, 13).Value = "Yes " Then
            Rows(i).EntireRow.Delete
        End If
    Next i
End Sub
0

There are 0 best solutions below