Harshil Mehta
Board Regular
- Joined
- May 14, 2020
- Messages
- 85
- Office Version
- 2013
- Platform
- Windows
Hi, I am trying to delete the entire row from 2 sheets in one go if it finds a match from another sheet.
The below code shows an error and highlights UNION. Got no idea how to fix this.
The below code shows an error and highlights UNION. Got no idea how to fix this.
VBA Code:
Sub custom_Remove_Entities_NewTemp()
Dim Cl As Range, Rng As Range
Dim v1, v2, v3(), i, j, k, r, c, nr As Long
Dim Ary As Variant, Nary As Variant
Dim Dic As Object
Dim colSheets As Collection
Set colSheets = New Collection
colSheets.Add Worksheets("Old.Temp")
colSheets.Add Worksheets("New.Temp")
For Each Worksheet In colSheets
Set Dic = CreateObject("scripting.dictionary")
With Sheets("Definition.Temp")
For Each Cl In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
Dic(Cl.Value) = Cl.Value
Next Cl
End With
For Each Cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
If Dic.Exists(Cl.Value) Then
If Rng Is Nothing Then Set Rng = Cl Else Set Rng = Union(Rng, Cl)
End If
Next Cl
If Not Rng Is Nothing Then Rng.EntireRow.Delete
Next
Set colSheets = Nothing
End Sub