Public Sub Tableau()
Dim i As Long, j As Long, Dlgn As Long, Dcol As Long, c As Range
Dim a, b, Mondico, Mdc
Application.ScreenUpdating = False
Dlgn = Sheets("Feuil1").Cells(Rows.Count, 1).End(xlUp).Row
Dcol = Sheets("Feuil1").Cells(1, Columns.Count).End(xlToLeft).Column
'Effacement de la feuille 2
Feuil2.UsedRange.Clear
'Report des semaines
Sheets("Feuil1").Rows(1).Copy Destination:=Sheets("Feuil2").Rows(1)
'Création de la listevdes articles
Set Mondico = CreateObject("Scripting.Dictionary")
a = Sheets("Feuil1").Range("B2", Sheets("Feuil1").Cells(Dlgn, Dcol).Address).Value
For Each b In a
Mondico(b) = b
Next b
Mdc = Mondico.Count
With Sheets("Feuil2")
.Cells(2, 1).Resize(Mondico.Count, 1) = Application.Transpose(Mondico.keys)
'Tri de la liste des articles
Call Tri(.Range("A1:A" & Mdc), 1, Mdc)
'Remplissage du tableau par les machines
For i = 2 To Dlgn
For j = 2 To Dcol
With .Range("A2:A" & Mdc)
Set c = .Find(Sheets("Feuil1").Cells(i, j), LookIn:=xlValues)
If Not c Is Nothing Then
c.Offset(, j - 1) = c.Offset(, j - 1) & ", " & Sheets("Feuil1").Cells(i, 1)
End If
End With
Next j
Next i
For i = 2 To Mdc 'suppression des premières virgules
For j = 2 To Dcol
.Cells(i, j) = Mid(.Cells(i, j), 2)
Next j
Next i
End With
Application.ScreenUpdating = True
Set c = Nothing
End Sub
Sub Tri(a, gauc, droi) ' Tri rapide
ref = a((gauc + droi) \ 2)
g = gauc: d = droi
Do
Do While a(g) < ref: g = g + 1: Loop
Do While ref < a(d): d = d - 1: Loop
If g <= d Then
temp = a(g): a(g) = a(d): a(d) = temp
g = g + 1: d = d - 1
End If
Loop While g <= d
If g < droi Then Call Tri(a, g, droi)
If gauc < d Then Call Tri(a, gauc, d)
End Sub