Sub CompareArrays()
On Error GoTo veryEnd
Dim Rng1 As Range
Dim rng2 As Range
Dim Count1 As Long
Dim Count2 As Long
Dim tB1 As Boolean
Dim tB2 As Boolean
Dim ComTex1 As String
Dim ComTex2 As String
Dim s1 As String
Dim oCell As Range
Dim Counter As Long
Dim RunV1 As Double
Dim RunV2 As Double
Dim i As Long
Dim j As Long
Dim R1C As Long
Dim R2C As Long
R1C = 0
R2C = 0
Dim Tolerance As Double
Tolerance = 0.1
Dim Mat1() As Double
Dim Mat2() As Double
Dim Mat1A() As Variant
Dim Mat2B() As Variant
Dim RM1() As Range
Dim RM2() As Range
On Error GoTo veryEnd
Set Rng1 = Application.InputBox(prompt:="select first range", Default:=ActiveCell, Type:=8)
Set rng2 = Application.InputBox(prompt:="select second range", Default:=ActiveCell, Type:=8)
On Error GoTo 0
Count1 = Rng1.Cells.Count
Count2 = rng2.Cells.Count
ReDim Mat1(1 To Count1) As Double
ReDim Mat2(1 To Count2) As Double
ReDim RM1(1 To Count1) As Range
ReDim RM2(1 To Count2) As Range
ReDim Mat1A(1 To 2 ^ Count1 - 1, 0 To 1) As Variant
ReDim Mat2B(1 To 2 ^ Count2 - 1, 0 To 1) As Variant
For Each oCell In Rng1.Cells
R1C = R1C + 1
Mat1(R1C) = oCell.Value
If oCell.Comment Is Nothing Then oCell.AddComment
oCell.Comment.Text Text:="""Range 1, Cell " & R1C & """" & Chr(10)
Set RM1(R1C) = oCell
Next oCell
For Each oCell In rng2.Cells
R2C = R2C + 1
Mat2(R2C) = oCell.Value
If oCell.Comment Is Nothing Then oCell.AddComment
oCell.Comment.Text Text:="""Range 2, Cell " & R2C & """" & Chr(10)
Set RM2(R2C) = oCell
Next oCell
m = 1
For i = 1 To Count1
k = 0
For j = 1 To i
k = k + 2 ^ (j - 1)
Next j
For p = m To k
If p = k Then
Mat1A(p, 0) = Mat1(i)
Mat1A(p, 1) = CStr(i)
Else
Mat1A(p, 0) = Mat1A(p - m + 1, 0) + Mat1(i)
Mat1A(p, 1) = Mat1A(p - m + 1, 1) & "," & CStr(i)
End If
Next p
m = k + 1
Next i
m = 1
For i = 1 To Count2
k = 0
For j = 1 To i
k = k + 2 ^ (j - 1)
Next j
For p = m To k
If p = k Then
Mat2B(p, 0) = Mat2(i)
Mat2B(p, 1) = CStr(i)
Else
Mat2B(p, 0) = Mat2B(p - m + 1, 0) + Mat2(i)
Mat2B(p, 1) = Mat2B(p - m + 1, 1) & "," & CStr(i)
End If
Next p
m = k + 1
Next i
For i = 1 To 2 ^ Count1 - 1
For j = 1 To 2 ^ Count2 - 1
If Mat1A(i, 0) = Mat2B(j, 0) Then
ComTex1 = Mat1A(i, 1)
ComTex2 = Mat2B(j, 1)
'~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
s1 = ""
tB1 = False
For k = 1 To Len(Mat1A(i, 1))
If Mid(Mat1A(i, 1), k, 1) = "," Then
RM1(CLng(s1)).Interior.Color = 49407
ComTex1 = RM1(CLng(s1)).Comment.Text & Chr(10) & "R1: " & Mat1A(i, 1) & Chr(10) & _
"R2: " & Mat2B(j, 1)
RM1(CLng(s1)).Comment.Text Text:=ComTex1
RM1(CLng(s1)).Comment.Shape.TextFrame.AutoSize = True
s1 = ""
Else
s1 = s1 & Mid(Mat1A(i, 1), k, 1)
End If
Next k
'~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
RM1(CLng(s1)).Interior.Color = 49407
ComTex1 = RM1(CLng(s1)).Comment.Text & Chr(10) & "R1: " & Mat1A(i, 1) & Chr(10) & _
"R2: " & Mat2B(j, 1)
RM1(CLng(s1)).Comment.Text Text:=ComTex1
RM1(CLng(s1)).Comment.Shape.TextFrame.AutoSize = True
'~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
s1 = ""
For k = 1 To Len(Mat2B(j, 1))
If Mid(Mat2B(j, 1), k, 1) = "," Then
RM2(CLng(s1)).Interior.Color = 49407
ComTex2 = RM2(CLng(s1)).Comment.Text & Chr(10) & "R2: " & Mat2B(j, 1) & Chr(10) & _
"R1: " & Mat1A(i, 1)
RM2(CLng(s1)).Comment.Text Text:=ComTex2
RM2(CLng(s1)).Comment.Shape.TextFrame.AutoSize = True
s1 = ""
Else
s1 = s1 & Mid(Mat2B(j, 1), k, 1)
End If
Next k
'~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
RM2(CLng(s1)).Interior.Color = 49407
ComTex2 = RM2(CLng(s1)).Comment.Text & Chr(10) & "R2: " & Mat2B(j, 1) & Chr(10) & _
"R1: " & Mat1A(i, 1)
RM2(CLng(s1)).Comment.Text Text:=ComTex2
RM2(CLng(s1)).Comment.Shape.TextFrame.AutoSize = True
'~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~'
End If
Next j
Application.StatusBar = Format(i / ((2 ^ (Count1) - 1)), "0.0%")
Next i
Application.StatusBar = ""
veryEnd:
End Sub