Re: Userform, Liste déroulante dépendante sans doublon | ||
---|---|---|
Inscription: 25/01/2021
De France
Messages:
3
Système d'exploitation: pc Version Excel utilisée: 365 |
Posté le : 29-01-2021 15h07
onjour Didier, Option Explicit Dim Ws As Worksheet Dim NbLignes As Integer Private Sub UserForm_Initialize() 'Définit la feuille contenant les données Set Ws = Worksheets("P") 'Définit le nombre de lignes dans la colonne A NbLignes = Ws.Range("I6000").End(xlUp).Row 'Remplissage du ComboBox1 Alim_Combo 1 End Sub Private Sub ComboBox1_Change() 'Remplissage Combo2 Alim_Combo 2, ComboBox1.Value End Sub Private Sub ComboBox2_Change() 'Remplissage Combo3 Alim_Combo 3, ComboBox2.Value End Sub 'Procédure pour alimenter les ComboBox Private Sub Alim_Combo(CbxIndex As Integer, Optional Cible As Variant) Dim j As Integer Dim Obj As Control 'Définit le ComboBox à remplir Set Obj = Me.Controls("ComboBox" & CbxIndex) 'Supprime les anciennes données Obj.Clear 'alimente le Combobox initial (Combobox1) If CbxIndex = 1 Then 'Boucle sur les lignes de la colonne A (à partir de la 2eme ligne) For j = 2 To NbLignes Obj = Ws.Range("I" & j) 'Remplit le ComboBox sans doublons If Obj.ListIndex = -1 Then Obj.AddItem Ws.Range("I" & j) Next j Else 'Alimentation conditionnelle des autres Combobox en fonction de 'ce qui est sélectionnée dans le contrôle précédent : '(La sélection du ComboBox1 définit le contenu du ComboBox2, 'La sélection du ComboBox2 définit le contenu du ComboBox3 ?etc...) For j = 2 To NbLignes If Ws.Range("I" & j).Offset(0, CbxIndex - 2) = Cible Then Obj = Ws.Range("I" & j).Offset(0, CbxIndex - 1) If Obj.ListIndex = -1 Then Obj.AddItem Ws.Range("I" & j).Offset(0, CbxIndex - 1) End If Next j End If 'Enlève la sélection dans le ComboBox Obj.ListIndex = -1 Dim i As Integer Dim Plage As Range Set Plage = Range("T_Compte") With ListBox1 .List() = Plage.Value .ColumnCount = Plage.Columns.Count For i = 1 To .ColumnCount Next End With End Sub
Il ne me reste plus qu'a regrouper les colonnes L à Q dans la listbox1 qui dépend des combobox1,2,3
|
|
|
Re: Userform, Liste déroulante dépendante sans doublon | ||
---|---|---|
Inscription: 25/01/2021
De France
Messages:
3
Système d'exploitation: pc Version Excel utilisée: 365 |
Posté le : 26-01-2021 21h01
Bonjour Didier,
Pour expliquer simplement, à partir de la valeur sélectionnée dans la liste L_TC (Plage "L_TC"), je souhaite voir afficher la liste des tiers (Plage "L_Tiers") qui y répondent. (critère étant dans la plage "V_TC")
exemple 1 exemple 2 L_TC = Charge L_TC = Produit L_Tiers L_Tiers 4.0.1.1.1_Microsoft 4.1.1.99_Clients_Divers 4.0.1.1.2_OVH 4.0.1.1.3_K2-Système 4.0.1.1.4_Citroën 4.0.1.1.5_Rexcel 4.0.1.1.6_Panasonic 4.0.1.1.5_SMA 4.0.1.1.8_Expert_Comptable 4.0.4.1.1_Rexcel 4.0.4.1.2_LDLC
Il s'agit d'un non-choix, je ne connais pas la différente d'impact dans la rapidité de l'exécution du code, j'ai modifié le fichier en conséquent ci-joint
Edité par Theo44 le 28/01/2021 11:51:52
|
|
|
Userform, Liste déroulante dépendante sans doublon | ||
---|---|---|
Inscription: 25/01/2021
De France
Messages:
3
Système d'exploitation: pc Version Excel utilisée: 365 |
Posté le : 25-01-2021 11h15
Bonjour, Private Sub Fermer_click() Unload Me End Sub Private Sub UserForm_Initialize() Set P = Sheets("P") Me.L_TC.List = P.Range("H3:H" & P.[H2500].End(xlUp).Row).Value Set mondico = CreateObject("Scripting.Dictionary") a = P.Range("j2:j" & P.[j5000].End(xlUp).Row) ' tableau a(n,1) pour rapidité For i = LBound(a) To UBound(a) If a(i, 1) <> "" Then mondico(a(i, 1)) = "" Next i 'Me.L_Tiers.List = MonDico.keys '--avec tri temp = mondico.keys Call Tri(temp, LBound(temp), UBound(temp)) Me.L_Tiers.List = temp Me.L_Cat.List = P.Range("k2:k" & P.[k2500].End(xlUp).Row).Value Me.L_Comptes.List = P.Range("l2:q" & P.[q2500].End(xlUp).Row).Value End Sub Sub Tri(a, gauc, droi) ' Quick sort ref = a((gauc + droi) \ 2) g = gauc: d = droi Do Do While a(g) < ref: g = g + 1: Loop Do While ref < 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
Edité par Theo44 le 25/01/2021 17:28:43
|
|
|