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 CommandButton1_Click()
LISTE
End Sub
Sub LISTE()
ListBox1.Clear
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim Cpt As Integer
Dim cpteuros As Double
Dim MtntSeuil As Double
Sheets("DONNEES").Select ' on selectionne la feuille DONNEES
With Sheets("DONNEES")
For i = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
If Cells(i, "C") = "AR" Then ' on boucle pour inscrire dans la listbox que les lignes de la feuilles où le type est "AR"
ListBox1.AddItem .Cells(i, "A"): ListBox1.List(ListBox1.ListCount - 1, 1) = Format(.Cells(i, "B"), "####.00 "): ListBox1.List(ListBox1.ListCount - 1, 2) = .Cells(i, "C")
End If
Next
End With
For j = 0 To ListBox1.ListCount - 1
MtntSeuil = MtntSeuil + ListBox1.Column(1, j) ' ici on boucle pour calculer l'addition de chaque ligne jusqu'à atteindre la valeur cible de la textbox1
If MtntSeuil < TextBox1.Value Then ListBox1.Selected(j) = True Else ListBox1.Selected(j) = False
Next j
For k = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(k) Then Cpt = Cpt + 1 'ici on boucle pour calculer le nombre de lignes selectionnées et calculer le montant que l'on affichera dans les textbox 2 et 3
If ListBox1.Selected(k) Then cpteuros = cpteuros + ListBox1.Column(1, k)
Next k
TextBox2.Value = Cpt
TextBox3.Value = Format(cpteuros, "####.00 ")
End Sub
Private Sub CommandButton2_Click()
Call fermerformulaire
End Sub
Private Sub ListBox1_Change()
Dim k As Integer
Dim cpteuros As Double
Dim Cpt As Integer
For k = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(k) Then Cpt = Cpt + 1 'ici on boucle pour tout changement de selection afin de mettre à jour les textbox2 et 3
If ListBox1.Selected(k) Then cpteuros = cpteuros + ListBox1.Column(1, k)
Next k
TextBox2.Value = Cpt
TextBox3.Value = Format(cpteuros, "####.00 ")
End Sub
Private Sub TextBox1_AfterUpdate()
TextBox1.Value = Format(TextBox1.Value, "####.00 ")
End Sub
Private Sub TextBox1_Change()
TextBox1.Value = Replace(TextBox1.Value, ".", ",")
End Sub |
Partager