Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

XL 2010 Liste en cascade avec historique des éléments de la cellule

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

idylh

XLDnaute Nouveau
Bonjour,

J'ai créé une liste en cascade sur 3 niveaux à partir d'un exemple de boisgontier. J'ai rajouté la notion de sans doublon, MultiSelectExtended et modifié la séparation des données.
Par contre, quand je retourne sur ma cellule pour rajouter et/ou supprimer des éléments je suis obligée de tout remplir de nouveau.
Est-il possible de garder les infos déjà remplis sur les 3 niveaux lorsque je retourne sur ma cellule?
Merci pour votre aide.

Code:
Dim f
Private Sub UserForm_Initialize()
  Set f = Sheets("BD")
  Set mondico = CreateObject("Scripting.Dictionary")
  For Each c In Range(f.[A2], f.[A65000].End(xlUp)) 
  mondico(c.Value) = c.Value
  Next c
  Me.ListBox1.List = mondico.items
  Me.ListBox1.MultiSelect = fmMultiSelectExtended
End Sub

Private Sub ListBox1_Change() 
  Me.ListBox3.Clear
  Set mondico = CreateObject("Scripting.Dictionary")
  For Each c In Range(f.[A2], f.[A65000].End(xlUp))
  For k = 0 To Me.ListBox1.ListCount - 1 
  If Me.ListBox1.Selected(k) = True Then
  If c = Me.ListBox1.List(k, 0) Then
  temp = c.Offset(, 1)
  mondico(temp) = temp
  End If
  End If
  Next k
  Next c
  Var = mondico.items
  Me.ListBox2.List = mondico.items
End Sub

Private Sub ListBox2_Change()

Dim mondico As Object
Set mondico = CreateObject("Scripting.Dictionary")
  Me.ListBox3.Clear
  For Each c In Range(f.[B2], f.[B65000].End(xlUp))
  For k = 0 To Me.ListBox2.ListCount - 1
  If Me.ListBox2.Selected(k) = True Then
  If c = Me.ListBox2.List(k, 0) Then
  
  If Not mondico.exists(c.Offset(, 1).Value) Then 
  mondico.Add c.Offset(, 1).Value, c.Offset(, 1).Value 
  Me.ListBox3.AddItem c.Offset(, 1)
  End If
  End If
  End If
  Next k
  Next c
End Sub

Private Sub b_ok_Click()
  temp = ""
  For k = 0 To Me.ListBox1.ListCount - 1
  If Me.ListBox1.Selected(k) = True Then temp = temp & Me.ListBox1.List(k, 0) & ","
  Next k
  If Len(temp) > 0 Then temp = Left(temp, Len(temp) - 1)
  ActiveCell = temp
  
  temp = ""
  For k = 0 To Me.ListBox2.ListCount - 1
  If Me.ListBox2.Selected(k) = True Then temp = temp & Me.ListBox2.List(k, 0) & ","
  Next k
  If Len(temp) > 0 Then temp = Left(temp, Len(temp) - 1)
  ActiveCell.Offset(, 1) = temp
  temp = ""
  For k = 0 To Me.ListBox3.ListCount - 1
  If Me.ListBox3.Selected(k) = True Then temp = temp & Me.ListBox3.List(k, 0) & ","
  Next k
  If Len(temp) > 0 Then temp = Left(temp, Len(temp) - 1)
  ActiveCell.Offset(, 2) = temp
  
  Unload Me
End Sub
 
bonjour
idylh bienvenue
voilà un début pour garder les sélections
pour la suite il faudrait un fichier
Code:
Option Explicit
Public a1(), a2(), a(3)

Private Sub b_ok_Click()
    Dim i As Long, j As Long, nbSelect As Byte
    temp = ""
    For k = 0 To Me.ListBox1.ListCount - 1
        If Me.ListBox1.Selected(k) = True Then temp = temp & Me.ListBox1.List(k, 0) & ",": nbSelect = nbSelect + 1
    Next k
    If Len(temp) > 0 Then temp = Left(temp, Len(temp) - 1)
    ActiveCell = temp
    ReDim a1(nbSelect - 1): nbSelect = 0
    temp = ""
    For k = 0 To Me.ListBox2.ListCount - 1
        If Me.ListBox2.Selected(k) = True Then temp = temp & Me.ListBox2.List(k, 0) & ",": nbSelect = nbSelect + 1
    Next k
    If Len(temp) > 0 Then temp = Left(temp, Len(temp) - 1)
    ActiveCell.Offset(, 1) = temp
    ReDim a2(nbSelect - 1): nbSelect = 0
    temp = ""
    For k = 0 To Me.ListBox3.ListCount - 1
        If Me.ListBox3.Selected(k) = True Then temp = temp & Me.ListBox3.List(k, 0) & ",": nbSelect = nbSelect + 1
    Next k
    If Len(temp) > 0 Then temp = Left(temp, Len(temp) - 1)
    ActiveCell.Offset(, 2) = temp
        ReDim a3(nbSelect - 1)

    For i = 1 To 3
        j = 0
        For k = 0 To Me("ListBox" & i).ListCount - 1
            If Me("ListBox" & i).Selected(k) Then
                Select Case i
                Case 1
                    a1 (j): a1(j) = k: j = j + 1

                Case 2
                    a2 (j): a2(j) = k: j = j + 1

                Case 3
                    a2 (j): a2(j) = k: j = j + 1

                End Select
            End If
        Next i
        Unload Me
    End Sub
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
3
Affichages
665
Réponses
4
Affichages
177
Réponses
3
Affichages
504
Réponses
10
Affichages
281
Réponses
4
Affichages
505
Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…