Alimenter plusieurs combobox

Bonjour,

Je souhaiterai savoir comment alimenter plusieurs combobox ?

En effet j'en ai déjà alimenté une avec le code suivant :

Private Sub UserForm_Initialize()

Dim c As Range

Dim tablo As New Collection

On Error Resume Next

With Sheets("Feuil1")

For Each c In .Range("C15:C" & .Range("C" & .Rows.Count).End(xlUp).Row)

tablo.Add c.Value, CStr(c.Value)

Next c

On Error GoTo 0

For Each Item In tablo

Me.ComboBox1.AddItem Item

Next

End With

End Sub

Mais comment en alimenter plusieurs sur le même userform ?

Merci

Bonjour,

Une piste :

Private Sub UserForm_Initialize()

    Dim c As Range
    Dim tablo As New Collection
    Dim Item

    On Error Resume Next

    With Sheets("Feuil1")

        '1er combo avec colonne C
        For Each c In .Range("C15:C" & .Range("C" & .Rows.Count).End(xlUp).Row)

            tablo.Add c.Value, CStr(c.Value)

        Next c

        For Each Item In tablo

            Me.ComboBox1.AddItem Item

        Next

        'vide la collection pour une seconde utilisation (un dictionnaire est plus rapide !)
        Set tablo = Nothing

        '2 ème combo avec colonne D
        For Each c In .Range("D15:D" & .Range("D" & .Rows.Count).End(xlUp).Row)

            tablo.Add c.Value, CStr(c.Value)

        Next c

        For Each Item In tablo

            Me.ComboBox2.AddItem Item

        Next

        'vide la collection à nouveau
        Set tablo = Nothing

        '3 ème combo avec colonne E
        For Each c In .Range("E15:E" & .Range("E" & .Rows.Count).End(xlUp).Row)

            tablo.Add c.Value, CStr(c.Value)

        Next c

        For Each Item In tablo

            Me.ComboBox3.AddItem Item

        Next

        On Error GoTo 0

    End With

End Sub

mais tu peux aussi utiliser 3 collections pour un remplissage dans une seule boucle. Comme dit en commentaire, un dictionnaire est plus rapide qu'une collection.

Hervé.

Rechercher des sujets similaires à "alimenter combobox"