as there is some problem with attaching files, here is the code with comments
Option Explicit
Sub test()
Dim data, result, rcount As Long, temp, Data1str As String, Data2str As String, i As Long, j As Long, n As Integer, m As Long
With Sheets("Data-Comparison-sheet")
'check if there is any data to process
If .Cells(Rows.Count, 1).End(xlUp).Row = 6 And .Cells(Rows.Count, 6).End(xlUp).Row = 6 Then Exit Sub
'take data table to array plus two more columns
data = .Range("a7", .Cells(.UsedRange.Rows.Count, 1)).Resize(, 11)
'array rows count to variable
rcount = UBound(data)
'dimensions set for result array
ReDim result(1 To rcount, 1 To 9)
'join Data ID and Data version for Data1 and Data2
For i = 1 To rcount
temp = "," & data(i, 1) & "|" & data(i, 2) & ","
If temp <> "" Then
If InStr(Data1str, temp) = 0 Then
Data1str = Data1str & temp
'saving each joined string to array column 10
data(i, 10) = temp
End If
End If
temp = "," & data(i, 6) & "|" & data(i, 7) & ","
If temp <> "" Then
If InStr(Data2str, temp) = 0 Then
Data2str = Data2str & temp
'saving each joined string to array column 10
data(i, 11) = temp
End If
End If
Next
'main loop checking if the joined string Data2str contains Data1 value and vice versa
For i = 1 To rcount
If InStr(Data2str, data(i, 10)) = 0 Then
'row counter for result Data1
j = j + 1
'if data is absent place it to result array
For n = 6 To 9
result(j, n) = data(i, n - 5)
Next
End If
If InStr(Data1str, data(i, 11)) = 0 Then
'row counter for result Data2
m = m + 1
'if data is absent place it to result array
For n = 1 To 4
result(m, n) = data(i, n + 5)
Next
End If
Next
Application.ScreenUpdating = 0
'checking if clearing range required to output result array
If Application.CountA(Range("k7"), Range("p7")) > 0 Then .UsedRange.Offset(6, 10).Resize(, 9).ClearContents
'if no differencies found exit sub
If j = 0 And m = 0 Then Exit Sub
'decide which result data is longer measuring number of rows filled
If j >= m Then .Range("k7").Resize(j, 9) = result Else .Range("k7").Resize(m, 9) = result
Application.ScreenUpdating = 1
End With
End Sub
Bookmarks