copier contenu listbox sue feuille excel

  • Initiateur de la discussion Initiateur de la discussion dam3117
  • 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 !

dam3117

XLDnaute Occasionnel
Bonjour le forum,

J'ai une listbox avec plusieurs lignes et colonnes et je voudrai copier le contenu sur une feuille excel.
voici mon code

Private Sub CommandButton2_Click()
Dim xlig As Long


Workbooks.Open Filename:= _
ThisWorkbook.Path & "\bilan.xls"
Windows("bilan.xls").Activate

xlig = Range("a65536").End(xlUp).Row + 1




Range("B5") = CDate(Label2)
For x = 0 To XXXXXXXXXXX JE PENSE QUE PROBLEME EST LA


Cells(xlig, 1) = UserForm18.ListBox1.List(x, 0)
Cells(xlig, 2) = UserForm18.ListBox1.List(x, 1)
Cells(xlig, 3) = UserForm18.ListBox1.List(x, 2)
Cells(xlig, 4) = UserForm18.ListBox1.List(x, 3)
Cells(xlig, 5) = UserForm18.ListBox1.List(x, 4)
Cells(xlig, 6) = UserForm18.ListBox1.List(x, 5)
Cells(xlig, 7) = UserForm18.ListBox1.List(x, 6)
Cells(xlig, 8) = UserForm18.ListBox1.List(x, 7)
Cells(xlig, 9) = UserForm18.ListBox1.List(x, 8)
x = x + 1
Next x

ActiveWorkbook.Save

End Sub

merci
 
Re : copier contenu listbox sue feuille excel

Bonjour,


Pas besoin de X=X+1 la boucle for s'en charge
ListCount = nombre d'items de la liste dont les index commence à 0
Inutile de rappeler Userform18 si la macro est dans le module du userForm
Code:
'With est plus rapide que le rappel de la liste à chaque boucle
With UserForm18.ListBox1 'Ou ListBox1 sans userForm18
For x = 0 To .ListCount-1
 
 
Cells(xlig+X, 1) = .List(x, 0)
Cells(xlig+X, 2) = .List(x, 1)
Cells(xlig+X, 3) = .List(x, 2)
Cells(xlig+X, 4) = .List(x, 3)
Cells(xlig+X, 5) = .List(x, 4)
Cells(xlig+X, 6) = .List(x, 5)
Cells(xlig+X, 7) = .List(x, 6)
Cells(xlig+X, 8) = .List(x, 7)
Cells(xlig+X, 9) = .List(x, 8)
 
Next x
End With

A+
 
- 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
533
Réponses
17
Affichages
2 K
Réponses
10
Affichages
843
Réponses
3
Affichages
834
Réponses
4
Affichages
581
Retour