Adaptation Liste en cascade

MaximeRoth

XLDnaute Junior
Bonjour,

J'ai récemment demandé de l'aide pour adapter une liste en cascade de Jacques BOISGONTIER à l'un de mes projets.
La demande à aboutie et mon proto projet fontionne bien. Cependant j'ai maintenant un autre problème
Voici le code de ma liste en cascade :


Code:
Private li As Integer 'déclare la variable li (LIgne)

Private Sub CommandButton1_Click()
search.Hide
Home.Show

End Sub

Private Sub ScrollBar1_Change()

End Sub

Private Sub Label24_Click()

End Sub

Private Sub Label28_Click()

End Sub

Private Sub UserForm_Initialize()
With Sheets("Numero_de_Serie")
    .Range("E9:AA" & .Cells(Application.Rows.Count, 2).End(xlUp).Row).Name = "Ma_Plage"
End With
End Sub
Private Sub ComboBox1_DropButtonClick()
  noCol = 1: ListeCol 1
End Sub
Private Sub ComboBox2_DropButtonClick()
  noCol = 2: ListeCol 2
End Sub
Private Sub ComboBox3_DropButtonClick()
  noCol = 3: ListeCol 3
End Sub
Private Sub ComboBox4_DropButtonClick()
  noCol = 4: ListeCol 4
End Sub
Private Sub ComboBox5_DropButtonClick()
  noCol = 5: ListeCol 5
End Sub
Private Sub ComboBox6_DropButtonClick()
  noCol = 6: ListeCol 6
End Sub
Private Sub ComboBox7_DropButtonClick()
  noCol = 7: ListeCol 7
End Sub
Private Sub ComboBox8_DropButtonClick()
  noCol = 8: ListeCol 8
End Sub
Private Sub ComboBox9_DropButtonClick()
  noCol = 9: ListeCol 9
End Sub
Private Sub ComboBox10_DropButtonClick()
  noCol = 10: ListeCol 10
End Sub
Private Sub ComboBox11_DropButtonClick()
  noCol = 11: ListeCol 11
End Sub
Private Sub ComboBox12_DropButtonClick()
  noCol = 12: ListeCol 12
End Sub
Private Sub ComboBox13_DropButtonClick()
  noCol = 13: ListeCol 13
End Sub
Private Sub ComboBox14_DropButtonClick()
  noCol = 14: ListeCol 14
End Sub
Private Sub ComboBox15_DropButtonClick()
  noCol = 15: ListeCol 15
End Sub
Private Sub ComboBox16_DropButtonClick()
  noCol = 16: ListeCol 16
End Sub
Private Sub ComboBox17_DropButtonClick()
  noCol = 17: ListeCol 17
End Sub
Private Sub ComboBox18_DropButtonClick()
  noCol = 18: ListeCol 18
End Sub
Private Sub ComboBox19_DropButtonClick()
  noCol = 19: ListeCol 19
End Sub
Private Sub ComboBox20_DropButtonClick()
  noCol = 20: ListeCol 20
End Sub
Private Sub ComboBox21_DropButtonClick()
  noCol = 21: ListeCol 21
End Sub
Private Sub ComboBox22_DropButtonClick()
  noCol = 22: ListeCol 22
End Sub
Sub ListeCol(noCol)
  Set MonDico = CreateObject("Scripting.Dictionary")
  For I = 1 To [Ma_Plage].Rows.Count
    ok = True
    For n = 1 To [Ma_Plage].Columns.Count
      If n <> noCol Then
        If Not Range("Ma_Plage").Cells(I, n) Like Me("comboBox" & n) Then ok = False
      End If
    Next n
    If ok Then
       tmp = Range("Ma_Plage").Cells(I, noCol)
       MonDico(tmp) = tmp
    End If
  Next I
  MonDico.Add "*", "*"
  temp = MonDico.items
  Call Tri(temp, LBound(temp), UBound(temp))
  Me("ComboBox" & noCol).List = temp
End Sub
Sub Tri(a, gauc, droi) ' Quick sort
  ref = CStr(a((gauc + droi) \ 2))
  g = gauc: d = droi
  Do
    Do While CStr(a(g)) < ref: g = g + 1: Loop
    Do While ref < CStr(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
Private Sub Combobox1_Change()
  filtre
End Sub
Private Sub ComboBox2_Change()
  filtre
End Sub
Private Sub ComboBox3_Change()
  filtre
End Sub
Private Sub ComboBox4_Change()
  filtre
End Sub
Private Sub ComboBox5_Change()
  filtre
End Sub
Private Sub Combobox6_Change()
  filtre
End Sub
Private Sub ComboBox7_Change()
  filtre
End Sub
Private Sub ComboBox8_Change()
  filtre
End Sub
Private Sub ComboBox9_Change()
  filtre
End Sub
Private Sub ComboBox10_Change()
  filtre
End Sub
Private Sub Combobox11_Change()
  filtre
End Sub
Private Sub ComboBox12_Change()
  filtre
End Sub
Private Sub ComboBox13_Change()
  filtre
End Sub
Private Sub ComboBox14_Change()
  filtre
End Sub
Private Sub ComboBox15_Change()
  filtre
End Sub
Private Sub Combobox16_Change()
  filtre
End Sub
Private Sub ComboBox17_Change()
  filtre
End Sub
Private Sub ComboBox18_Change()
  filtre
End Sub
Private Sub ComboBox19_Change()
  filtre
End Sub
Private Sub ComboBox20_Change()
  filtre
End Sub
Private Sub ComboBox21_Change()
  filtre
End Sub
Private Sub ComboBox22_Change()
  filtre
End Sub
Sub filtre()
   ligne = 0
   Me.ListBox1.Clear
   For I = 1 To [Ma_Plage].Rows.Count
     ok = True
     For n = 1 To [Ma_Plage].Columns.Count
         If Not Range("Ma_Plage").Cells(I, n) Like Me("comboBox" & n) Then ok = False
     Next n
     If ok Then
       Me.ListBox1.AddItem
       For k = 1 To [Ma_Plage].Columns.Count
         Me.ListBox1.List(ligne, k - 1) = Range("Ma_Plage").Cells(I, k)
       Next k
       Me.ListBox1.List(ligne, 5) = I 'récupère le numéro de la ligne i(-1)
       ligne = ligne + 1
      End If
   Next I
   On Error Resume Next
  ' ActiveSheet.ShowAllData
  ' [A1].AutoFilter Field:=1, Criteria1:=Me.ComboBox1
  ' If Me.ComboBox2 <> "*" Then [A5].AutoFilter Field:=2, Criteria1:=Me.ComboBox2
  ' [A1].AutoFilter Field:=3, Criteria1:=Me.ComboBox3
  ' [A1].AutoFilter Field:=4, Criteria1:=Me.ComboBox4
End Sub
Private Sub CommandButton2_Click() 'bouton "Modifier"
For x = 1 To 5 'boucle sur les 4 textboxes
    Sheets("Numero_de_Serie").Cells(li, x + 1) = Me.Controls("TextBox" & x).Value 'place la valeur de la textbox dans l'onglet Ma_Plage
Next x 'prochaine textbox de la boucle
Unload Me
F_Interro.Show
End Sub

Private Sub ListBox1_Click() 'au clic dans la ListBox1
li = Me.ListBox1.Column(5, Me.ListBox1.ListIndex) + 8 'récupère le numéro de la ligne sélectionnée
'remplissage des textboxes
For x = 1 To 5 'boucle sur les 4 textboxes
    Me.Controls("TextBox" & x).Value = Sheets("Numero_de_Serie").Cells(li, x + 4) 'récupère la valeur dans la textbox
Next x 'prochaine textbox de la boucle
End Sub

Pour le fichier test je n'avais que une cascade à 5 niveaux. Cependant le projet a évolué et la cascade est passé à 22 niveaux.
J'ai donc changé ma plage en conséquence passée de E9:I ==> E9:AA.
Cependant le programme plante. J'ai bien édité ma listbox où apparaissent les solutions et le code pour rajouter les nouvelles comboboxes.

J'aurais donc souhaité savoir si quelqu'un à déjà eu ce genre de problème ou si tout simplement il y a une longueur maximum de plage ?

Merci d'avance.

Max
 

Pièces jointes

  • Numéro de Série Proto V13 31052012.zip
    140.2 KB · Affichages: 33
Dernière édition:

Discussions similaires

Statistiques des forums

Discussions
312 520
Messages
2 089 286
Membres
104 086
dernier inscrit
lucasjol