Création d'une arborescence en plusieurs colonnes à partir de deux colonnes

Bonjour à tous,

J'espère que vous allez bien :)

Petit sujet simple dans la demande mais qui me cause quelques problèmes.

J'ai à ce jour un fichier répertoriant des pièces/familles de pièces en 2 colonnes :

  1. La 1ère donne la désignation de l'élément
  2. La 2ème donne le parent de l'élément (qui a sa désignation existante dans la 1ère colonne)

Je cherche à créer facilement une arborescence sur plusieurs colonnes pour rendre les choses plus lisibles.

C'est à dire, prendre les données "parents/enfants" de ces deux colonnes et les répartir sur plusieurs colonnes pour chaque niveau de parenté.

Quelqu'un aurait-il une idée SVP :) ?

Je vous ai joint un fichier simple pour exemple.

J'ai à faire la même chose avec un fichier avec quelques milliers de lignes...

Merci d'avance pour votre aide !

Bonsoir

J'arrive à recréer l'arborescence, mais avec des doublons pour chaque parent. Il doit suffire de supprimer les doublons, mais je vois pas trop comment faire.

Sub arborescence()
Dim nomA As String
Dim NomB As String

Dim ligneA As Integer
Dim ligneB As Integer
Dim ligneC As Integer
ligneC = "3"
Dim test As Integer

' phase 1 = niveau 3
For ligneA = 3 To 10
test = "0"
    If Not IsEmpty(Cells(ligneA, 1)) Then
    nomA = Cells(ligneA, 1)

For ligneB = 3 To 10
    If Not IsEmpty(Cells(ligneB, 2)) And Cells(ligneB, 2) = nomA Then
    test = test + 1

End If

Next ligneB

If test = 0 Then

Cells(ligneC, 6) = nomA

ligneC = ligneC + 1
End If

End If
Next ligneA

' phase deux = niveau 2

For ligneA = 3 To 10
    If Not IsEmpty(Cells(ligneA, 6)) Then
    nomA = Cells(ligneA, 6)

For ligneB = 3 To 10
    If Not IsEmpty(Cells(ligneB, 1)) And Cells(ligneB, 1) = nomA Then
    Cells(ligneA, 5) = Cells(ligneB, 2)

End If
Next ligneB

End If
Next ligneA

' phase 3 = niveau 1

For ligneA = 3 To 10
    If Not IsEmpty(Cells(ligneA, 5)) Then
        nomA = Cells(ligneA, 5)

For ligneB = 3 To 10
    If Not IsEmpty(Cells(ligneB, 1)) And Cells(ligneB, 1) = nomA Then
        Cells(ligneA, 4) = Cells(ligneB, 2)

    End If
Next ligneB

    End If
Next ligneA

End Sub

Bonjour à tous

Une solution PowerPivot qu'il faudrait faire évoluer si plus de 3 niveaux

Une solution PowerQuery qui reproduit sensiblement la solution PowerPivot mais qui prend jusqu'à 7 niveaux

Ce n'est pas ma production mais une adaptation de solutions trouvées sur le net

96arborescence.xlsx (185.13 Ko)

bonjour,

une proposition via une macro

Bonjour à tous !

Bonjour à tous

Une solution PowerPivot qu'il faudrait faire évoluer si plus de 3 niveaux

Une solution PowerQuery qui reproduit sensiblement la solution PowerPivot mais qui prend jusqu'à 7 niveaux

Ce n'est pas ma production mais une adaptation de solutions trouvées sur le net

Merci de partager cette trouvaille ! Impressionnant.

Ayé, j'ai trouvé. La nuit porte conseil. Il n'y a qu'à adapter !

Sub arborescence()
Dim nomA As String
Dim NomB As String

Dim ligneA As Integer
Dim ligneB As Integer
Dim ligneC As Integer
ligneC = "3"
Dim test As Integer

For ligneA = 3 To 1000
test = "0"
    If Not IsEmpty(Cells(ligneA, 1)) Then
    nomA = Cells(ligneA, 1)

For ligneB = 3 To 1000
    If Not IsEmpty(Cells(ligneB, 2)) And Cells(ligneB, 2) = nomA Then
    test = test + 1

End If

Next ligneB

If test = 0 Then

Cells(ligneC, 6) = nomA

ligneC = ligneC + 1
End If

End If
Next ligneA

' phase deux = niveau 2

For ligneA = 3 To 1000
    If Not IsEmpty(Cells(ligneA, 6)) Then
    nomA = Cells(ligneA, 6)

For ligneB = 3 To 1000
    If Not IsEmpty(Cells(ligneB, 1)) And Cells(ligneB, 1) = nomA Then
    Cells(ligneA, 5) = Cells(ligneB, 2)

End If
Next ligneB

End If
Next ligneA

' suppression doublons phase 2

For ligneA = 3 To 1000
    If Not IsEmpty(Cells(ligneA, 5)) Then
    nomA = Cells(ligneA, 5)

For ligneB = ligneA + 1 To 1000
    If Not IsEmpty(Cells(ligneB, 5)) And Cells(ligneB, 5) = nomA Then
    Cells(ligneB, 5) = ""

End If
Next ligneB

End If
Next ligneA

' phase 3 = niveau 1

For ligneA = 3 To 1000
    If Not IsEmpty(Cells(ligneA, 5)) Then
        nomA = Cells(ligneA, 5)

For ligneB = 3 To 1000
    If Not IsEmpty(Cells(ligneB, 1)) And Cells(ligneB, 1) = nomA Then
        Cells(ligneA, 4) = Cells(ligneB, 2)

    End If
Next ligneB

    End If
Next ligneA

' suppression doublons phase 3

For ligneA = 3 To 1000
    If Not IsEmpty(Cells(ligneA, 4)) Then
    nomA = Cells(ligneA, 4)

For ligneB = ligneA + 1 To 1000
    If Not IsEmpty(Cells(ligneB, 4)) And Cells(ligneB, 4) = nomA Then
    Cells(ligneB, 4) = ""

End If
Next ligneB

End If
Next ligneA

End Sub

Bonjour à tous,

@78Chris, , comment peut on créer ces niveaus dans powerpivot ?

Bonjour à tous

@78Chris, , comment peut on créer ces niveaus dans powerpivot ?

Si tu ouvres le modèle de données tu pourras voir toutes les formules. Ensuite j'ai créé un TCD

J'ai trouvé une vidéo expliquant cela et l'ai suivi mais j'ai tellement fouillé que je ne retrouve plus laquelle j'ai finalement utilisée dans mon historique de navigation

Pour PowerQuery la source dont je suis parti est https://codereview.stackexchange.com/questions/236267/resolve-parent-child-hierarchy-in-power-query-...

Bonjour à tous,

Merci pour vos retours c'est ce que je cherchais ! :)

Je vais pouvoir appliquer cela !

Bonne journée

merci,

c'est inconnu, je dois explorer cela ...

bonjour,

une solution vba

Rechercher des sujets similaires à "creation arborescence colonnes partir deux"