For a first trial see next code, some comestic adjustments need to be done , but first comment
Option Explicit
Sub CheckData()
Dim ObjDic1 As Object
Dim ObjDic2 As Object
Dim ObjDic11 As Object
Dim ObjDic22 As Object
Dim F As Range
Dim TEMP
Dim LastRow As Long, LastRow1 As Long, LastRow2 As Long
Dim G
Dim AAA, BBB
Set ObjDic1 = CreateObject("Scripting.Dictionary")
Set ObjDic11 = CreateObject("Scripting.Dictionary")
Set ObjDic2 = CreateObject("Scripting.Dictionary")
Set ObjDic22 = CreateObject("Scripting.Dictionary")
LastRow = 5: LastRow1 = 5: LastRow2 = 5
'----- DICTIONARY PREPARATION
With Sheets("Structure_DATA")
For Each F In Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp))
ObjDic1.Item(F.Value) = F.Resize(1, 5)
TEMP = F & F.Offset(0, 1) & F.Offset(0, 2) & F.Offset(0, 3) & F.Offset(0, 4)
ObjDic11.Item(TEMP) = F.Resize(1, 5)
Next F
End With
With Sheets("XML_DATA")
For Each F In Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp))
ObjDic2.Item(F.Value) = F.Resize(1, 5)
TEMP = F & F.Offset(0, 1) & F.Offset(0, 2) & F.Offset(0, 3) & F.Offset(0, 4)
ObjDic22.Item(TEMP) = F.Resize(1, 5)
Next F
End With
'----- ADDED ITEM
With Sheets("Structure_DATA")
For Each F In Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp))
If (ObjDic2.exists(F.Value)) Then ObjDic2.Remove (F.Value)
Next F
Sheets("Structure_XML_Comparison").Cells(LastRow, 1) = "Added Items"
Sheets("Structure_XML_Comparison").Cells(LastRow, 8).Resize(ObjDic2.Count, 5) = Application.Transpose(Application.Transpose(ObjDic2.Items))
LastRow = LastRow + ObjDic2.Count + 1
End With
'----- REMOVED ITEMS
With Sheets("XML_DATA")
For Each F In Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp))
If (ObjDic1.exists(F.Value)) Then ObjDic1.Remove (F.Value)
Next F
Sheets("Structure_XML_Comparison").Cells(LastRow, 1) = "Removed Items"
Sheets("Structure_XML_Comparison").Cells(LastRow, 2).Resize(ObjDic1.Count, 5) = Application.Transpose(Application.Transpose(ObjDic1.Items))
LastRow = LastRow + ObjDic1.Count + 1
End With
'----- UNCHANGED ITEMS
ObjDic2.RemoveAll
For Each G In ObjDic11
If Not (ObjDic22.exists(G)) Then
ObjDic2.Item(Application.Index(ObjDic11.Item(G), 1, 1)) = ObjDic11.Item(G)
ObjDic11.Remove (G)
End If
Next G
For Each G In ObjDic2
If (ObjDic1.exists(G)) Then
ObjDic2.Remove (G)
End If
Next G
Sheets("Structure_XML_Comparison").Cells(LastRow, 1) = "Unchanged Items"
Sheets("Structure_XML_Comparison").Cells(LastRow, 2).Resize(ObjDic11.Count, 5) = Application.Transpose(Application.Transpose(ObjDic11.Items))
Sheets("Structure_XML_Comparison").Cells(LastRow, 8).Resize(ObjDic11.Count, 5) = Application.Transpose(Application.Transpose(ObjDic11.Items))
LastRow = LastRow + ObjDic11.Count + 1
'----- MODIFIED ITEMS
Sheets("Structure_XML_Comparison").Cells(LastRow, 1) = "Modified Items"
Sheets("Structure_XML_Comparison").Cells(LastRow, 2).Resize(ObjDic2.Count, 5) = Application.Transpose(Application.Transpose(ObjDic2.Items))
Sheets("Structure_XML_Comparison").Cells(LastRow, 8).Resize(ObjDic2.Count, 5) = Application.Transpose(Application.Transpose(ObjDic2.Items))
End Sub
Bookmarks