• Initiateur de la discussion Initiateur de la discussion lynyrd
  • Date de début Date de début

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 !

lynyrd

XLDnaute Impliqué
Bonjour le forum
Y a t'il un moyen de rendre cette macro valide avec plus de 10 listbox
Merci.

Option Explicit
Option Compare Text
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub TextBox1_Change()
Dim Plage As Range, cell As Range
Dim Recherche As String, Adresse As String
Dim Ligne As Integer, N As Integer
Dim C As Range
ListBox1.Clear
N = 0
Recherche = TextBox1.Value
Range("A1").Select
Ligne = Sheets("Feuil2").Range("A" & "65536").End(xlUp).Row
Set Plage = Sheets("Feuil2").Range("a" & "1:" & "a" & Ligne)
With Plage
Set C = .Find(Recherche, , xlValues)
If Not C Is Nothing Then
Adresse = C.Address
Do
If UCase(Recherche) = UCase(Left(C, Len(Recherche))) Then
ListBox1.AddItem C.Offset(0, 0), N
ListBox1.List(N, 0) = C
ListBox1.List(N, 1) = C.Offset(0, 1)
ListBox1.List(N, 2) = C.Offset(0, 2)
ListBox1.List(N, 3) = C.Offset(0, 3)
ListBox1.List(N, 4) = C.Offset(0, 4)
ListBox1.List(N, 5) = C.Offset(0, 5)
ListBox1.List(N, 6) = C.Offset(0, 6)
ListBox1.List(N, 7) = C.Offset(0, 7)
ListBox1.List(N, 8) = C.Offset(0, 8)
ListBox1.List(N, 9) = C.Offset(0, 9)
ListBox1.List(N, 10) = C.Offset(0, 10)
ListBox1.List(N, 11) = C.Offset(0, 11)


N = N + 1
End If
Set C = .FindNext(C)
Loop While Not C Is Nothing And C.Address <> Adresse
End If
End With
End Sub
Private Sub UserForm_Initialize()
ListBox1.ColumnCount = 12
ListBox1.ColumnWidths = "100;40;40;40;40;100;100;40;40;40;40;100"
End Sub
 
Re : plus de 10 listbox

Bonjour lynyrd,

Déjà pour ListeBox1, vous devez simplifier ceci :

Code:
ListBox1.List(N, 0) = C
ListBox1.List(N, 1) = C.Offset(0, 1)
ListBox1.List(N, 2) = C.Offset(0, 2)
ListBox1.List(N, 3) = C.Offset(0, 3)
ListBox1.List(N, 4) = C.Offset(0, 4)
ListBox1.List(N, 5) = C.Offset(0, 5)
ListBox1.List(N, 6) = C.Offset(0, 6)
ListBox1.List(N, 7) = C.Offset(0, 7)
ListBox1.List(N, 8) = C.Offset(0, 8)
ListBox1.List(N, 9) = C.Offset(0, 9)
ListBox1.List(N, 10) = C.Offset(0, 10)
ListBox1.List(N, 11) = C.Offset(0, 11)

par :

Code:
For j = 0 To 11
ListBox1.List(N, j) = C.Offset(0, j)
Next

Ensuite s'il y a 10 ListBox (au besoin, modifiez leurs noms pour avoir les bons numéros), faites encore une boucle (je n'ai rien testé du tout) :

Code:
For i = 1 To 10
'------------(pas étudié ce qu'il y a là)
Me.Controls("ListBox" & i).AddItem C, N 'je crois que Me. est inutile
For j = 0 To 11
Me.Controls("ListBox" & i).List(N, j) = C.Offset(0, j)
Next
'----------
Next

EDITION : avec Option Explicit, n'oubliez pas de déclarer i et j As Byte

A+
 
Dernière édition:
- 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
10
Affichages
669
Réponses
5
Affichages
915
Retour