Sheet1 in test.xlsm includes 2 columns listing different fruits (column A) and type (Column B). I would like to delete rows that do not equal "Mango". The "Mango" criteria is listed in Sheet1 in Criteria.xlsm. Problem: everything is deleted but the 2nd row that has fruit "Grape". What should happen is that only rows that don't have the fruit "Mango" should be deleted.
Here is my code and it is executed in Sheet1 in test.xlsm (Both files (test and Criteria) attached. Thank you so much!
Sub DeleteDifferentWorkbook()
Application.ScreenUpdating = False
Dim iRow As Integer
Dim lr As Long
Dim List As Variant
Dim y As Workbook
lr = ThisWorkbook.Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
Set y = Workbooks.Open("C:\Users\jojoshu\Desktop\VBA Test\Criteria.xlsm")
List = y.Worksheets("Sheet1").Cells(2, "A").Value
For iRow = lr To 1 Step -1
If Cells(iRow, "A").Value <> List Then
ThisWorkbook.Worksheets("Sheet1").Rows(iRow).Delete
End If
Next iRow
Application.ScreenUpdating = True
End Sub
Bookmarks