Private Sub Worksheet_Activate()
Dim d As Object, r As Range, tablo, i&, x$, y$, z$, n&, dest As Range, s
Set d = CreateObject("Scripting.Dictionary")
d.CompareMode = vbTextCompare 'la casse est ignotée
Set r = Sheets("DONNEE").[A1].CurrentRegion.Resize(, 19)
tablo = r 'matrice, plus rapide
For i = 2 To UBound(tablo)
If tablo(i, 19) = 1 Then 'colonne S
If Not r.Rows(i).Hidden Then 'lignes non masquées
x = tablo(i, 13) & Chr(1) & tablo(i, 11) 'concaténation avec séparateur
y = tablo(i, 5)
If y <> "" Then
y = r(i, 7).Interior.Color & Chr(2) & y 'concatène le code couleur
If d.exists(x) Then
If InStr(Chr(1) & d(x) & Chr(1), Chr(1) & y & Chr(1)) = 0 Then d(x) = d(x) & Chr(1) & y 'encadrement du nom de la machine
Else
d(x) = y
End If
End If
End If
End If
Next i
'---restitution---
Application.ScreenUpdating = False
Cells.Delete 'RAZ
Set dest = [A1] '1ère cellule, à adapter
dest = "PARC": dest(1, 2) = "ZONE": dest(1, 3) = "MACHINE"
n = d.Count
If n = 0 Then Exit Sub
dest(2).Resize(n) = Application.Transpose(d.keys) 'attention, Transpose est limitée à 65536 lignes
dest(2).Resize(n).TextToColumns dest(2), xlDelimited, Other:=True, OtherChar:=Chr(1) 'commande Convertir
dest(2, 3).Resize(n) = Application.Transpose(d.items)
dest.Resize(n + 1, 3).Sort dest, xlAscending, Header:=xlYes 'tri alphabétique sur PARC
dest(2, 3).Resize(n).TextToColumns dest(2, 3), xlDelimited, Other:=True, OtherChar:=Chr(1)
With dest(1, 3).Resize(, dest.CurrentRegion.Columns.Count - 2)
.Merge 'fusionne
.HorizontalAlignment = xlCenter 'centre
.Select
End With
'---colore les cellules---
For Each r In UsedRange
s = Split(r, Chr(2))
If UBound(s) = 1 Then
r.Interior.Color = s(0)
r = s(1) 'supprime le code couleur
End If
Next r
End Sub