Private Sub CommandButton1_Click()
Dim Tb, dMat As Object, dNom As Object, i As Integer, j As Integer, dl As Long
Me.ListBox1.Clear
Set plage = F.[b4].CurrentRegion
Set dMat = CreateObject("scripting.dictionary")
Set dNom = CreateObject("scripting.dictionary")
Tb = F.Range("A5:Q" & F.Range("A" & Rows.Count).End(xlUp).Row).Value
For i = 1 To UBound(Tb)
dMat(Tb(i, 2)) = dMat(Tb(i, 2)) + Tb(i, 16)
dNom(Tb(i, 3)) = ""
Next i
For j = 0 To dMat.Count - 1
Me.ListBox1.AddItem
ListBox1.List(ListBox1.ListCount - 1, 0) = j + 1
ListBox1.List(ListBox1.ListCount - 1, 1) = dMat.keys()(j)
ListBox1.List(ListBox1.ListCount - 1, 2) = dNom.keys()(j)
ListBox1.List(ListBox1.ListCount - 1, 3) = FormatNumber(dMat.items()(j), 3)
'textbox2=limite de remboursement----textbox1=valeur de remboursement
If ListBox1.List(ListBox1.ListCount - 1, 3) < Val(TextBox2.Value) Then
ListBox1.List(ListBox1.ListCount - 1, 4) = FormatNumber((dMat.items()(j) / 2), 3)
ListBox1.List(ListBox1.ListCount - 1, 5) = FormatNumber((dMat.items()(j) / 2), 3)
Else
ListBox1.List(ListBox1.ListCount - 1, 4) = FormatNumber((dMat.items()(j) - Val(TextBox1.Value)), 3)
ListBox1.List(ListBox1.ListCount - 1, 5) = FormatNumber(CSng(TextBox1.Value), 3)
End If
Next j
Call Cumul
End Sub
Private Sub Cumul()
'ici code pour mettre à jour textbox3,4 et 5
Dim i As Integer
If Me.ListBox1.ListCount <> 0 Then
Dim T As Single, T1 As Single, T2 As Single 'déclare la variable T (Total) / Type à adapter
With ListBox1 'prend en compte la ListBox1 (à adapter)
For i = 0 To .ListCount - 1 'boucle sur tous les lignes de la ListBox1
T = T + .Column(3, i) 'définit le total T
T1 = T1 + .Column(4, i)
T2 = T2 + .Column(5, i)
Next i 'prochaine ligne de la boucle
TextBox3.Value = Format(T, "#,##0.000") 'renvoie dans la TextBox1 le total T (à adapter)
TextBox4.Value = Format(T1, "#,##0.000")
TextBox5.Value = Format(T2, "#,##0.000")
End With 'fin de la prise en compte de la ListBox1
End If
End Sub