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 11/12/2011, 18h28   #1
Membre habitué
 
Homme christian
retraite
Inscription : avril 2010
Messages : 310
Détails du profil
Informations personnelles :
Nom : Homme christian
Âge : 56
Localisation : Espagne

Informations professionnelles :
Activité : retraite
Secteur : Industrie

Informations forums :
Inscription : avril 2010
Messages : 310
Points : 109
Points : 109
Par défaut Criteres de selection

bonjour
je cherche a tri ma listview avec un combobox.

voici mon code:
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
Code Visual Basic :
 
Private Sub CommandButton1_Click()
Me.Hide
Sheets("Menu").Select
End Sub
 
Private Sub Barbecue_Click()
 Load Barbecues
 Barbecues.Show
 Unload UserForm1
 UserForm1.Show
 Sheets("Menu").Select
End Sub
 
 
Private Sub Retour_Menu_Click()
 Sheets("Menu").Select
 Range("P5").Select
 Application.DisplayFormulaBar = False
 Unload UserForm1
 End Sub
 
Private Sub TextBox1_Change()
Me.TextBox1 = Sheets("Barbecue").Range("I2")
End Sub
Private Sub userform_activate()
 
 Sheets("Barbecue").Select
 Application.DisplayFullScreen = True
 
 TextBox1.Value = Sheets("Barbecue").Range("I2").Value
 
 
 
With Me
.StartUpPosition = 3
.Width = Application.Width
.Height = Application.Height
.Left = 0
.Top = 0
End With
 
'Suppression des titres de colonnes
ListView1.ColumnHeaders.Clear
 
'Alimentation des titres de colonne :
 
ListView1.ColumnHeaders.Add , , "Mois", ListView1.Width * 0.1, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "Nom", ListView1.Width * 0.22, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "Nº MobilHome", ListView1.Width * 0.15, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "Duree", ListView1.Width * 0.1, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "Reglement", ListView1.Width * 0.12, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "Prix Location", ListView1.Width * 0.13, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "Total", ListView1.Width * 0.08, lvwColumnRight
ListView1.ColumnHeaders.Add , , "Caution", ListView1.Width * 0.1, lvwColumnCenter
 
'on remplit la listview
 
With Me.ListView1
.ListItems.Clear
    For Each V In Range("A4:A" & Range("A65536").End(xlUp).Row)
        X = X + 1
        .ListItems.Add , , V.Text
        .ListItems(X).ForeColor = V.Font.Color
 
        For j = 1 To 8
            .ListItems(X).ListSubItems.Add , , V.Offset(0, j).Text
            .ListItems(X).ListSubItems(j).ForeColor = V.Offset(0, j).Font.Color
 
        Next j
Next V
End With
 
End Sub


a l'aide d'un combobox ou j'ai une liste des mois de l'annee
apres choix dans ce comboboxavoir l'affichage du mois choisi ainsi que ses donnees
dans le combobox
Tous les mois
Janvier
Février
Mars
etc...

cris
chris09300 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/12/2011, 18h45   #2
Expert Confirmé Sénior
 
Avatar de Qwazerty
 
Homme Stéphane
La très haute tension :D
Inscription : avril 2002
Messages : 2 446
Détails du profil
Informations personnelles :
Nom : Homme Stéphane
Âge : 32
Localisation : France

Informations professionnelles :
Activité : La très haute tension :D
Secteur : Service public

Informations forums :
Inscription : avril 2002
Messages : 2 446
Points : 4 620
Points : 4 620
Envoyer un message via MSN à Qwazerty
Salut

Je suppose qu'une fois un mois choisi dans ta ComboBox, tu souhaites n'afficher dans le listBox que les données correspondante au mois sélectionné?
Si c'est bien ça dis nous dans quelle colonne de ton tableau le mois apparaît-il?

++
Qwaz
__________________

MagicQwaz := Harry Potter la baguette en moins
Le monde dans lequel on vit
HammerFest
Ma page perso DVP - Dernier Tutoriel : VBA & Internet Explorer
Qwazerty est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/12/2011, 18h49   #3
Membre habitué
 
Homme christian
retraite
Inscription : avril 2010
Messages : 310
Détails du profil
Informations personnelles :
Nom : Homme christian
Âge : 56
Localisation : Espagne

Informations professionnelles :
Activité : retraite
Secteur : Industrie

Informations forums :
Inscription : avril 2010
Messages : 310
Points : 109
Points : 109
c'est exactement cela, dans ma listview
dans la colonne A, et le debut des mois commence en A4.
chris09300 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/12/2011, 18h53   #4
Expert Confirmé Sénior
 
Avatar de Qwazerty
 
Homme Stéphane
La très haute tension :D
Inscription : avril 2002
Messages : 2 446
Détails du profil
Informations personnelles :
Nom : Homme Stéphane
Âge : 32
Localisation : France

Informations professionnelles :
Activité : La très haute tension :D
Secteur : Service public

Informations forums :
Inscription : avril 2002
Messages : 2 446
Points : 4 620
Points : 4 620
Envoyer un message via MSN à Qwazerty
Salut

Alors quelque chose comme ça devrait faire l'affaire (pas testé)

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
With Me.ListView1
    .ListItems.Clear
    For Each V In Range("A4:A" & Cells(Rows.Count, "A").End(xlUp).Row)
        'Ici on controle que le mois inscrit dans la tableau Excel correspond bien au moi choisi
        'Si aucun moi n'a été choisi, on inscrit toutes les données
        If (V.Value = ComboBox1.Text) Or (ComboBox1.Text = "") Then
            'On ajoute une ligne
            With .ListItems.Add(, , V.Text)
                .ForeColor = V.Font.Color
                For j = 1 To 8
                    .ListSubItems.Add , , V.Offset(0, j).Text
                    .ListSubItems(j).ForeColor = V.Offset(0, j).Font.Color
                Next j
            End With
        End If
    Next V
End With
++
Qwaz
__________________

MagicQwaz := Harry Potter la baguette en moins
Le monde dans lequel on vit
HammerFest
Ma page perso DVP - Dernier Tutoriel : VBA & Internet Explorer
Qwazerty est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/12/2011, 19h04   #5
Membre habitué
 
Homme christian
retraite
Inscription : avril 2010
Messages : 310
Détails du profil
Informations personnelles :
Nom : Homme christian
Âge : 56
Localisation : Espagne

Informations professionnelles :
Activité : retraite
Secteur : Industrie

Informations forums :
Inscription : avril 2010
Messages : 310
Points : 109
Points : 109
j'ai beau mettre n'importe quels mois , cela ne fonctionne pas.
la listview reste en etat
ci joint mon fichier
cris
Fichiers attachés
Type de fichier : rar Classeur1.rar (396,1 Ko, 1 affichages)
chris09300 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/12/2011, 19h33   #6
Expert Confirmé Sénior
 
Avatar de Qwazerty
 
Homme Stéphane
La très haute tension :D
Inscription : avril 2002
Messages : 2 446
Détails du profil
Informations personnelles :
Nom : Homme Stéphane
Âge : 32
Localisation : France

Informations professionnelles :
Activité : La très haute tension :D
Secteur : Service public

Informations forums :
Inscription : avril 2002
Messages : 2 446
Points : 4 620
Points : 4 620
Envoyer un message via MSN à Qwazerty
Salut

Dans ta Combobox tu as Janvier, Fevrier, Mars...
Et dans ta colonne A tu as quoi exactement?
[Edit]
Je viens de voir ton fichier, je regarde[/Edit]


++
Qwaz

Salut

Alors voila les modifications, lit bien les commentaires, il y a des propriétés de certains composants à modifier.

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
Private Sub ComboBox1_Change()
'On met a jour la liste
MaJList
End Sub
 
Private Sub TextBox1_Change()
'Inutile il suffit de passer sa propriété Enabled à False
'Me.TextBox1 = Sheets("Barbecue").Range("I2")
End Sub
Private Sub userform_activate()
' Sheets("Barbecue").Select
'Application.DisplayFullScreen = True 'désactiver pour les essais
 
'With Me
'    .StartUpPosition = 3
'    .Width = Application.Width
'    .Height = Application.Height
'    .Left = 0
'    .Top = 0
'End With
 
 
'Autant lier le textbox à la cellule I2
'Regarde dans les propriété du TextBox (ControlSource) et met comme valeur Barbecue!I2
'Regardes également la propriété Enabled du TextBox qui interdit la modification du contenu (met la False)
'TextBox1.Value = Sheets("Barbecue").Range("I2").Value
 
'On selectionne la 1er entré de la combobox "Tous les mois"
ComboBox1.ListIndex = 0 'La liste est mise a jour (execution de ComboBox1_Change())
 
 
End Sub
 
Sub MaJList()
 
'Dans les propriété de ta ComboBox, met Style à fmStyleDropDownList, sa interdit à l'utilisateur de pouvoir taper n'importequoi
Dim ShBarbeuc As Worksheet
'On pointe sur la feuille Barbecue
Set ShBarbeuc = ThisWorkbook.Sheets("Barbecue")
 
'Suppression des titres de colonnes
ListView1.ColumnHeaders.Clear
 
'Alimentation des titres de colonne :
'Ton fichier à planté au chargement et m'a viré le listView, je ne peux donc pas verifier ce que tu as mis comme propriété
'Mais tu doit avoir la propriété View à lvwReport
 
ListView1.ColumnHeaders.Add , , "Mois", ListView1.Width * 0.1, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "Nom", ListView1.Width * 0.22, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "Nº MobilHome", ListView1.Width * 0.15, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "Duree", ListView1.Width * 0.1, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "Reglement", ListView1.Width * 0.12, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "Prix Location", ListView1.Width * 0.13, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "Total", ListView1.Width * 0.08, lvwColumnRight
ListView1.ColumnHeaders.Add , , "Caution", ListView1.Width * 0.1, lvwColumnCenter
 
 
With Me.ListView1
    .ListItems.Clear
    For Each V In ShBarbeuc.Range("A4:A" & ShBarbeuc.Cells(Rows.Count, "A").End(xlUp).Row)
        'Ici on controle que le mois inscrit dans la tableau Excel correspond bien au moi choisi
        'Si aucun moi n'a été choisi, on inscrit toutes les données
        'On passe les valeur en majuscule Ucase) pour ne pas etre dérangé par les majuscule en début de nom
        'Décembre n'est pas égale à décembre
        If (UCase(V.Text) = UCase(ComboBox1.Text)) Or (ComboBox1.Text = "Tous les mois") Then
            'On ajoute une ligne
            With .ListItems.Add(, , V.Text)
                .ForeColor = V.Font.Color
                For j = 1 To 8
                    .ListSubItems.Add , , V.Offset(0, j).Text
                    .ListSubItems(j).ForeColor = V.Offset(0, j).Font.Color
                Next j
            End With
        End If
    Next V
End With
 
End Sub
++
Qwaz
__________________

MagicQwaz := Harry Potter la baguette en moins
Le monde dans lequel on vit
HammerFest
Ma page perso DVP - Dernier Tutoriel : VBA & Internet Explorer
Qwazerty est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/12/2011, 20h30   #7
Membre habitué
 
Homme christian
retraite
Inscription : avril 2010
Messages : 310
Détails du profil
Informations personnelles :
Nom : Homme christian
Âge : 56
Localisation : Espagne

Informations professionnelles :
Activité : retraite
Secteur : Industrie

Informations forums :
Inscription : avril 2010
Messages : 310
Points : 109
Points : 109
cela fonctionne partiellement
quand je lance l'userform il n'y a rien dans la lisview.
je met le combobox a janvier, j'ai la ligne janvier
idem quand je mets decembre.
mais quans je veux revenir a tous les mois
rien
chris09300 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/12/2011, 20h43   #8
Expert Confirmé Sénior
 
Avatar de Qwazerty
 
Homme Stéphane
La très haute tension :D
Inscription : avril 2002
Messages : 2 446
Détails du profil
Informations personnelles :
Nom : Homme Stéphane
Âge : 32
Localisation : France

Informations professionnelles :
Activité : La très haute tension :D
Secteur : Service public

Informations forums :
Inscription : avril 2002
Messages : 2 446
Points : 4 620
Points : 4 620
Envoyer un message via MSN à Qwazerty
Salut
Étonnant ça fonctionne chez moi.

Je te joins un fichier

++
Qwaz
Fichiers attachés
Type de fichier : zip Classeur1.zip (45,9 Ko, 2 affichages)
__________________

MagicQwaz := Harry Potter la baguette en moins
Le monde dans lequel on vit
HammerFest
Ma page perso DVP - Dernier Tutoriel : VBA & Internet Explorer
Qwazerty est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/12/2011, 21h27   #9
Membre habitué
 
Homme christian
retraite
Inscription : avril 2010
Messages : 310
Détails du profil
Informations personnelles :
Nom : Homme christian
Âge : 56
Localisation : Espagne

Informations professionnelles :
Activité : retraite
Secteur : Industrie

Informations forums :
Inscription : avril 2010
Messages : 310
Points : 109
Points : 109

merci beaucoup stephane,
ca fonctionne tres bien, j'avais dans la 1 ligne de combobox
ecrit chez moi Tous les Mois et non mois
merci je vais pouvoir faire de meme sur mes 12 autres feuilles
cris

excuse moi, juste une chose
le textbox avec le total m'interesse
je m'explique, comme il est actuellement, il reste fixe que je choisse tous les mois,ou simplement 1 mois, j'aurais souhaite que la valeur change en fonction du choix execute
cris
chris09300 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/12/2011, 22h38   #10
Expert Confirmé Sénior
 
Avatar de Qwazerty
 
Homme Stéphane
La très haute tension :D
Inscription : avril 2002
Messages : 2 446
Détails du profil
Informations personnelles :
Nom : Homme Stéphane
Âge : 32
Localisation : France

Informations professionnelles :
Activité : La très haute tension :D
Secteur : Service public

Informations forums :
Inscription : avril 2002
Messages : 2 446
Points : 4 620
Points : 4 620
Envoyer un message via MSN à Qwazerty
Salut

N'oublie pas vider la propriété ControleSource du TextBox.

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
Sub MaJList()
'il faut que tu supprimes ControleSource du TextBox1 dans les propriétés
Dim Total As Double
'Dans les propriété de ta ComboBox, met Style à fmStyleDropDownList, sa interdit à l'utilisateur de pouvoir taper n'importequoi
Dim ShBarbeuc As Worksheet
'On pointe sur la feuille Barbecue
Set ShBarbeuc = ThisWorkbook.Sheets("Barbecue")
 
'Suppression des titres de colonnes
ListView1.ColumnHeaders.Clear
 
'Alimentation des titres de colonne :
'Ton fichier à planté au chargement et m'a viré le listView, je ne peux donc pas verifier ce que tu as mis comme propriété
'Mais tu doit avoir la propriété View à lvwReport
 
ListView1.ColumnHeaders.Add , , "Mois", ListView1.Width * 0.1, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "Nom", ListView1.Width * 0.22, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "Nº MobilHome", ListView1.Width * 0.15, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "Duree", ListView1.Width * 0.1, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "Reglement", ListView1.Width * 0.12, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "Prix Location", ListView1.Width * 0.13, lvwColumnLeft
ListView1.ColumnHeaders.Add , , "Total", ListView1.Width * 0.08, lvwColumnRight
ListView1.ColumnHeaders.Add , , "Caution", ListView1.Width * 0.1, lvwColumnCenter
 
 
With Me.ListView1
    .ListItems.Clear
    For Each V In ShBarbeuc.Range("A4:A" & ShBarbeuc.Cells(Rows.Count, "A").End(xlUp).Row)
        'Ici on controle que le mois inscrit dans la tableau Excel correspond bien au moi choisi
        'Si aucun moi n'a été choisi, on inscrit toutes les données
        'On passe les valeur en majuscule Ucase) pour ne pas etre dérangé par les majuscule en début de nom
        'Décembre n'est pas égale à décembre
        If (UCase(V.Text) = UCase(ComboBox1.Text)) Or (ComboBox1.Text = "Tous les mois") Then
            'On ajoute une ligne
            With .ListItems.Add(, , V.Text)
                .ForeColor = V.Font.Color
                For j = 1 To 8
                    .ListSubItems.Add , , V.Offset(0, j).Text
                    .ListSubItems(j).ForeColor = V.Offset(0, j).Font.Color
                Next j
            End With
            'On calcul le total
            Total = Total + CDbl(V.Offset(0, 6))
        End If
    Next V
End With
 
'On place Total dans le TExtbox1
TextBox1.Text = CStr(Total)
End Sub
++
Qwaz
__________________

MagicQwaz := Harry Potter la baguette en moins
Le monde dans lequel on vit
HammerFest
Ma page perso DVP - Dernier Tutoriel : VBA & Internet Explorer
Qwazerty est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/12/2011, 22h45   #11
Membre habitué
 
Homme christian
retraite
Inscription : avril 2010
Messages : 310
Détails du profil
Informations personnelles :
Nom : Homme christian
Âge : 56
Localisation : Espagne

Informations professionnelles :
Activité : retraite
Secteur : Industrie

Informations forums :
Inscription : avril 2010
Messages : 310
Points : 109
Points : 109
nickel
bonne soireestephane
cris
chris09300 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 01h22.


 
 
 
 
Partenaires

Hébergement Web