Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Excel > Macros et VBA Excel
Macros et VBA Excel Vos questions relatives aux macros Excel, à l'utilisation de VBA et à l'automatisation de vos classeurs Excel.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 30/09/2011, 12h41   #1
Invité de passage
 
Homme
Inscription : septembre 2011
Messages : 3
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Secteur : Service public

Informations forums :
Inscription : septembre 2011
Messages : 3
Points : 0
Points : 0
Par défaut Listbox transfert de données

Bonjour à tous.
J'ai besoin d'un coup de main; voici mon problème:

J'ai 2 listbox. Dans la 1ère des données qui sont prises d'un tableau...

Ce que je voudrais c'est que lors du clic sur un "command button" les sélections faites sur la listbox1 se mette dans la listbox2....
En espérant avoir été clair, je vous remercie d'avance.
Batt04 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/09/2011, 13h01   #2
Expert Confirmé Sénior
 
Homme Daniel
aucune
Inscription : septembre 2011
Messages : 2 004
Détails du profil
Informations personnelles :
Nom : Homme Daniel
Localisation : France, Seine et Marne (Île de France)

Informations professionnelles :
Activité : aucune

Informations forums :
Inscription : septembre 2011
Messages : 2 004
Points : 4 037
Points : 4 037
Bonjour,

J'ai supposé que les listboxes étaient sur une feuille. Ca ne change pas beaucoup s'il elles ont sur un userform. Je n'ai pas non plus réinitialisé Listbox2 :

Code :
1
2
3
4
5
6
7
8
9
10
Private Sub CommandButton1_Click()
    With ActiveSheet
        For i = 0 To .ListBox1.ListCount - 1
            If .ListBox1.Selected(i) = True Then
                .ListBox2.AddItem .ListBox1.List(i)
                .ListBox1.Selected(i) = False
            End If
        Next i
    End With
End Sub
__________________
Cordialement.

Daniel

Citation:
La plus perdue de toutes les journées est celle où l'on n'a pas ri.
Chamfort
Daniel.C est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/09/2011, 13h25   #3
Invité de passage
 
Homme
Inscription : septembre 2011
Messages : 3
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Secteur : Service public

Informations forums :
Inscription : septembre 2011
Messages : 3
Points : 0
Points : 0
Par défaut Petit probleme ....

Bonjour, voici le code qui se trouve actuellement dans mon userform,

en fait le transfert doit se faire de la listbox1 à listbox3 par le commandbutton3

En faisant les modifications qui vont bien, ça ne fonctionne pas...


Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
Option Explicit
 
Private Sub CommandButton1_Click()
TextBox1 = Date
 
End Sub
 
Private Sub CommandButton2_Click()
Dim fin2 As Integer
Dim sec As Integer
Dim Y As Integer, X As Integer, A
 
If IsDate(TextBox1) = False Then MsgBox ("Manque la date"): Exit Sub
If TextBox1 = "" Then MsgBox ("Manque la date"): Exit Sub
If ListBox2.ListIndex = -1 Then MsgBox ("Manque la formation"): Exit Sub
If TextBox2 = "" Then MsgBox ("Manque la durée"): Exit Sub
 
fin2 = finf7 + 1
sec = PV + 1
 
Y = 8
A = 1
 
Feuil17.Cells(fin2, 1) = CDate(TextBox1)
Feuil17.Cells(fin2, 2) = ListBox2.ListIndex
Feuil17.Cells(fin2, 4) = Val(TextBox2)
Feuil17.Cells(fin2, 5) = TextBox3
 
For X = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(X) = True Then
Feuil17.Cells(fin2, Y) = ListBox1.List(X, 1) & " " & ListBox1.List(X, 2) & " " & ListBox1.List(X, 3): Y = Y + 1
Feuil14.Cells(PV, A) = ListBox1.List(X, 1) & " " & ListBox1.List(X, 2) & " " & ListBox1.List(X, 3): A = A + 1
Feuil18.Cells(X + 2, ListBox2.ListIndex + 2) = Feuil18.Cells(X + 2, ListBox2.ListIndex + 2) + Val(TextBox2)
 
End If
 
Next
TextBox1 = ""
TextBox2 = ""
 
Lfor
 
Me.Hide
End Sub
 
 
Private Sub CommandButton3_Click()
 
    With ActiveSheet
        For i = 0 To .ListBox1.ListCount - 1
            If .ListBox1.Selected(i) = True Then
                .ListBox3.AddItem .ListBox1.List(i)
                .ListBox1.Selected(i) = False
            End If
        Next i
    End With
 
End Sub
 
 
Private Sub ListBox1_Click()
 
End Sub
 
 
 
Private Sub UserForm_Activate()
 
Dim tablo As Variant
Dim derligne
TextBox1.Text = ""
With feuil9
derligne = .Range("a65536").End(xlUp).Row
tablo = .Range("a2:d" & derligne)
ListBox1.List = tablo
 
End With
With Feuil18
derligne = .Range("iu1").End(xlToLeft).Address
tablo = .Range("b1:" & derligne)
ListBox2.List = WorksheetFunction.Transpose(tablo)
 
End With
 
End Sub
Batt04 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/09/2011, 15h16   #4
Expert Confirmé Sénior
 
Homme Daniel
aucune
Inscription : septembre 2011
Messages : 2 004
Détails du profil
Informations personnelles :
Nom : Homme Daniel
Localisation : France, Seine et Marne (Île de France)

Informations professionnelles :
Activité : aucune

Informations forums :
Inscription : septembre 2011
Messages : 2 004
Points : 4 037
Points : 4 037
Ravi d'apprendre en dépouillant le code que ListBox1 est multicolumns. Est-ce qu'il faut reporter toutes les colonnes dans ListBox3 ?
Donne toutes les infos dès le premier message, tu fais gagner du temps à tout le monde.
__________________
Cordialement.

Daniel

Citation:
La plus perdue de toutes les journées est celle où l'on n'a pas ri.
Chamfort
Daniel.C est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 03h38.


 
 
 
 
Partenaires

Hébergement Web