[COLOR="Navy"]Sub[/COLOR] MG28Aug54
[COLOR="Navy"]Dim[/COLOR] Ray [COLOR="Navy"]As[/COLOR] Variant, Dn [COLOR="Navy"]As[/COLOR] Range, n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] oMax [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] K [COLOR="Navy"]As[/COLOR] Variant, st [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
Ray = ActiveSheet.Range("a7").CurrentRegion
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] Ac = 1 To 4
[COLOR="Navy"]For[/COLOR] n = 2 To UBound(Ray, 1)
[COLOR="Navy"]If[/COLOR] Not IsEmpty(Ray(n, Ac)) [COLOR="Navy"]Then[/COLOR]
[COLOR="Navy"]If[/COLOR] Not .Exists(Ray(n, Ac)) [COLOR="Navy"]Then[/COLOR]
.Add Ray(n, Ac), Ray(1, Ac)
[COLOR="Navy"]Else[/COLOR]
.Item(Ray(n, Ac)) = .Item(Ray(n, Ac)) & ", " & Ray(1, Ac)
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]Next[/COLOR] Ac
ReDim nray(1 To .Count, 1 To 6)
nray(1, 1) = "A to M": nray(1, 2) = "M to A": nray(1, 3) = "A to M, M to C"
nray(1, 4) = "C to M, M to A": nray(1, 5) = "M to C": nray(1, 6) = "C to M"
[COLOR="Navy"]For[/COLOR] Ac = 1 To 6
n = 1
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] K [COLOR="Navy"]In[/COLOR] .keys
st = IIf(.Item(K) = "M to A, C to M", "C to M, M to A", .Item(K))
[COLOR="Navy"]If[/COLOR] st = nray(1, Ac) [COLOR="Navy"]Then[/COLOR]
n = n + 1
nray(n, Ac) = K
oMax = Application.Max(oMax, n)
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] K
[COLOR="Navy"]Next[/COLOR] Ac
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]With[/COLOR] Range("F7").Resize(oMax, 6)
.Value = nray
.Columns.AutoFit
.Borders.Weight = 2
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]