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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| Option Explicit
Sub Nomenc()
Dim NewSh As Worksheet
Dim Dico As New Dictionary 'Object 'Si tu ne souhaites pas activer Scripting Runtime [Outil, Références...]
Dim iRow As Integer
Dim CA As String
Dim TmpV As Variant
'On instancie le dico ...Si tu ne souhaites pas activer Scripting Runtime [Outil, Références...]
'Set Dico = CreateObject("Scripting.Dictionary")
'On pointe le tableau de donnée
With Feuil1.ListObjects("Tab_Article")
'On boucle sur les lignes
For iRow = 1 To .ListRows.Count
'On Compléte le dico
CA = .DataBodyRange(iRow, .ListColumns("Code Article").Index)
If Dico(CA) <> "" Then Dico(CA) = Dico(CA) & ","
Dico(CA) = Dico(CA) & .DataBodyRange(iRow, .ListColumns("Repère").Index)
Next
End With
'On Crée le BOM si des données sont présentes
If Dico.Count > 0 Then
'On ajoute un onglet
Set NewSh = ThisWorkbook.Worksheets.Add
'On pointe le nouvel onglet
With NewSh
'On place l'entête
.Range("A1:C1").Value = Array("Code article", "Repères", "Qté")
'On crée un tableau structuré et on le pointe
With .ListObjects.Add(xlSrcRange, .Range("A1:C1"), , xlYes)
'On boucle sur le contenu du dico
For iRow = 0 To Dico.Count - 1
'On ajoute une ligne et on la pointe
With .ListRows.Add
'On place les infos
.Range(1, 1) = Dico.Keys(iRow)
.Range(1, 2) = Dico.Items(iRow)
.Range(1, 3) = UBound(Split(Dico.Items(iRow), ",")) + 1
End With
Next
End With
End With
End If
End Sub |
Partager