Trying to create a code which checks if the dictionary value exists in each cell and if exists then keep that range in memory using Union argument. However, I am facing error with Set Rng = MyRng(i, 1) Else Set Rng = Union(Rng, MyRng(i, 1)) line. Can anyone please help me understand what am I doing wrong?
VBA Code:
MyRng = .Range("V1:V" & .Cells(Rows.Count, "V").End(xlUp).Row).Value
For i = 2 To UBound(MyRng, 1)
If Dic.Exists(MyRng(i, 1)) Then
If Rng Is Nothing Then Set Rng = MyRng(i, 1) Else Set Rng = Union(Rng, MyRng(i, 1))
End If
Next i
If Not Rng Is Nothing Then Rng.EntireRow.Copy
Set Rng = Nothing