I am trying to create a code which checks if the Dictionary value exits or not in the Column A. If it does then check the value for 24th Column of that particular row. If the value in the 24th Column is not 7 or 4 then delete the entire row.
No error message is shown when I try to run the below code. However, the results are not as per the requirements. It simply deletes the rows when it finds the dictionary value.
No error message is shown when I try to run the below code. However, the results are not as per the requirements. It simply deletes the rows when it finds the dictionary value.
VBA Code:
Sub filter_test()
Dim Cl As Range, Rng As Range
Dim Dic As Object
Set Dic = CreateObject("scripting.dictionary")
'Add Key words to dictionary
With Sheets("Criteria.Temp")
For Each Cl In .Range("L2", .Range("L" & Rows.Count).End(xlUp))
Dic(Cl.Value) = Cl.Value
Next Cl
End With
'Delete key word's row from the Output sheet
With Sheets("Output")
For Each Cl In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
If Dic.Exists(Cl.Value) Then
If Cl.Offset(, 24) <> "7" Or Cl.Offset(, 24) <> "4" Then
If Rng Is Nothing Then Set Rng = Cl Else Set Rng = Union(Rng, Cl)
End If
End If
Next Cl
End With
If Not Rng Is Nothing Then Rng.EntireRow.Delete
Set Dic = Nothing
Set Rng = Nothing
End Sub