1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| Sub CreeListeBD()
colBD = 1
colListe = 8
Set f = Sheets("bd")
ligne = 1
f.Cells(ligne + 1, colListe).Resize(1000, 10).Clear
Set mondico = CreateObject("Scripting.Dictionary")
For Each c In Range(f.Cells(2, colBD), f.Cells(65000, colBD).End(xlUp))
mondico(c.Value) = c.Value
Next c
f.Cells(ligne, colListe) = "Liste"
f.Cells(ligne, colListe).Font.Bold = True
f.Cells(ligne + 1, colListe).Resize(mondico.Count) = Application.Transpose(mondico.items)
ActiveWorkbook.Names.Add Name:="Liste", RefersTo:=f.Cells(ligne + 1, colListe).Resize(mondico.Count)
'---- niv 2,3,..
For niv = 2 To 5 ' adapter le nombre de niveaux
colBD = colBD + 1
colListe = colListe + 2
ligne = 1
For Each c In Range(f.Cells(2, colListe - 2), f.Cells(65000, colListe - 2).End(xlUp))
If c <> "" And c.Font.Bold <> True Then
Set mondico = CreateObject("Scripting.Dictionary")
For Each d In Range(f.Cells(2, colBD), f.Cells(65000, colBD).End(xlUp))
If d.Offset(, -1) = c Then mondico(d.Value) = d.Value
Next d
f.Cells(ligne, colListe) = c
f.Cells(ligne, colListe).Font.Bold = True
f.Cells(ligne + 1, colListe).Resize(mondico.Count) = Application.Transpose(mondico.items)
ActiveWorkbook.Names.Add Name:=Replace(c, " ", "_"), RefersTo:=f.Cells(ligne + 1, colListe).Resize(mondico.Count)
ligne = ligne + mondico.Count + 1
End If
Next c
Next niv
End Sub |
Partager