Welcome to the forum.
Given this sheet:
Excel 2012
<tbody>
[TD="align: center"]1[/TD]
[TD="align: center"]2[/TD]
[TD="align: right"]-1[/TD]
[TD="align: right"]-1[/TD]
[TD="align: right"]-1[/TD]
[TD="align: right"]-4[/TD]
[TD="align: center"]3[/TD]
[TD="align: right"]-2[/TD]
[TD="align: right"]-3[/TD]
[TD="align: right"]-3[/TD]
[TD="align: right"]-41[/TD]
[TD="align: center"]4[/TD]
[TD="align: right"]-3[/TD]
[TD="align: right"]-10[/TD]
[TD="align: right"]-10[/TD]
[TD="align: right"]-42[/TD]
[TD="align: center"]5[/TD]
[TD="align: right"]-4[/TD]
[TD="align: right"]-20[/TD]
[TD="align: right"]-30[/TD]
[TD="align: right"]-50[/TD]
[TD="align: center"]6[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]-41[/TD]
[TD="align: right"][/TD]
[TD="align: center"]7[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"]-42[/TD]
[TD="align: right"][/TD]
</tbody>
Sheet1
This macro:
Code:
Sub Intersections()
Dim Dict() As Object, sht1 As Worksheet, sht2 As Worksheet, OutTab() As Variant
Dim lc As Long, r As Long, c As Long, ctr As Long, x As Variant
Set sht1 = Sheets("Sheet1")
Set sht2 = Sheets("Sheet2")
sht2.Cells.ClearContents
lc = sht1.Cells(1, Columns.Count).End(xlToLeft).Column
ReDim Dict(1 To lc)
ReDim OutTab(1 To lc + 1, 1 To lc + 1)
For c = 1 To lc
Set Dict(c) = CreateObject("Scripting.Dictionary")
d1 = sht1.Cells(1, c).Resize(sht1.Cells(Rows.Count, c).End(xlUp).Row).Value
For r = 2 To UBound(d1)
Dict(c)(d1(r, 1)) = 1
Next r
OutTab(c + 1, 1) = d1(1, 1)
OutTab(1, c + 1) = d1(1, 1)
Next c
For r = 1 To lc
For c = r To lc
If r = c Then
ctr = Dict(c).Count
Else
ctr = 0
For Each x In Dict(r)
If Dict(c).exists(x) Then ctr = ctr + 1
Next x
End If
OutTab(r + 1, c + 1) = ctr
OutTab(c + 1, r + 1) = ctr
Next c
Next r
sht2.Range("A1").Resize(lc + 1, lc + 1) = OutTab
End Sub
will create this sheet:
Excel 2012
| A | B | C | D | E |
---|
Set A | Set B | Set C | Set D | | |
Set A | | | | | |
Set B | | | | | |
Set C | | | | | |
Set D | | | | | |
<tbody>
[TD="align: center"]1[/TD]
[TD="align: right"][/TD]
[TD="align: center"]2[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]1[/TD]
[TD="align: center"]3[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]0[/TD]
[TD="align: center"]4[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]2[/TD]
[TD="align: center"]5[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]4[/TD]
</tbody>
Sheet2
Let me know if this is what you're looking for.