Sub TEST3()
Application.DisplayAlerts = False
ARR = Selection
Set D = CreateObject("scripting.dictionary")
For I = 1 To UBound(ARR, 2)
If ARR(1, I) = "" Then Exit Sub
If Not D.exists(ARR(1, I)) Then
D.Add ARR(1, I), 1
Else
D(ARR(1, I)) = D(ARR(1, I)) + 1
End If
Next
S = D.ITEMS
L = Selection.Column - 1
R = Selection.Row
For I = 0 To UBound(S)
If S(I) > 1 Then
With Range(Cells(R, L + 1), Cells(R, L + S(I)))
.Merge
.HorizontalAlignment = xlCenter
.Borders.LineStyle = xlContinuous
End With
Else
With Cells(R, L + 1)
.HorizontalAlignment = xlCenter
.Borders.LineStyle = xlContinuous
End With
End If
L = L + S(I)
Next
Application.DisplayAlerts = True
End Sub