Afficher un tableau dynamique dans une listbox

Bonjour,

Je souhaite afficher un tableau dans une listbox qui est dans une userforme.

De plus, il faudrait que cette listebox se filtre grâce à une combobox.

J'ai cherché sur différent forum mais je n'ai rien trouver à par Rowsource.

Merci de votre aide

Bonjour Gégé,

Voici un essai avec la même propriété List que pour la combobox :

dim Liste 'liste complète en mémoire, affectée à l'initialisation de l'UF
private sub userform_initialize()
with me
    Liste = Worksheets("Feuil2").Range("B2:D20").Value 'à adapter
    with .ListBox1
        .columncount = ubound(Liste,2)
        .List = Liste
    end with
end with
end sub

private sub combobox1_change()
with me
    t = Filtre(Liste, .combobox1.value, 1) 'liste filtrée (portant sur la colonne 1 du tableau Liste) d'après le texte contenu en combobox1
    with .listBox1
        .clear
        if isarray(t) then .list = t
    end with
end with
end sub

function Filtre(ArrSrc, Key$, optional Column as byte = 1)
dim temp()
if not isarray(ArrSrc) then exit function
on error resume next
NbCol = ubound(ArrSrc, 2): if err <> 0 then exit function
on error goto 0
if Column > NbCol or Column < lbound(ArrSrc, 2) then exit function
for i = lbound(ArrSrc) to ubound(ArrSrc)
    if ArrSrc(i, Column) like "*" & Key & "*" then
        n = n + 1: redim preserve temp(1 to ubound(ArrSrc, 2), 1 to n)
        for k = lbound(ArrSrc, 2) to ubound(ArrSrc, 2)
            temp(k, n) = ArrSrc(i, k)
        next k
    end if
next i
if n > 0 then Filtre = application.transpose(temp)
end function

Bon réveillon et bonne année si vous me lisez en 2022 !

Cdlt,

Bonjour

Bonjour à tous et bonne année

Une variante.

Bye !

Bonjour,

merci beaucoup pour vos deux réponses.

Bonne année

Rechercher des sujets similaires à "afficher tableau dynamique listbox"