Sub SommeParDates()
Dim jours As Range, article As Range, qte As Range, lig%, total
With Feuil1
Set jours = .Range("i2:i65536")
Set article = .Range("c2:c65536")
Set qte = .Range("d2:d65536")
End With
With Feuil2
lig = .Range("a65536").End(xlUp).Row + 1
.Cells(lig, 1) = lig - 1
.Cells(lig, 2) = Format(Feuil1.Cells(lig, 9), "dd.mm.yyyy")
.Cells(lig, 3) = Feuil1.Cells(lig, 3)
total = Application.SumIfs(qte, jours, .Cells(lig, 2), article, .Cells(lig, 3))
.Cells(lig, 4) = total
End With
End Sub
Private Sub ComboBox1_Click()
Call Sorties
End Sub
Private Sub Sorties()
Dim sItem As ListItem, cel As Range, premaddress
Application.ScreenUpdating = False
With Me.ListView1.ColumnHeaders
.Clear
.Add , , "Date", 1
.Add , , "Articles", 195
.Add , , "Sorties", 50, fmAlignmentRight
End With
On Error Resume Next
ListView1.ListItems.Clear
With Feuil2.Range("b2:b65536")
Set cel = .Find(ComboBox1, , xlValues)
If Not cel Is Nothing Then
premaddress = cel.Address
Do
Set sItem = ListView1.ListItems.Add(Text:=cel.Offset(0, 0))
sItem.SubItems(1) = cel.Offset(0, 1)
sItem.SubItems(2) = cel.Offset(0, 2)
Set cel = .FindNext(cel)
Loop While Not cel Is Nothing And cel.Address <> premaddress
End If
End With
End Sub
'----------------------------------------------------------
'Et pour supprimer les doublons; à mettre dans un module standard
Option Explicit
Sub Suppr_Doublons()
Dim m As Object, i As Long, z As Variant, sh As Worksheet
Set sh = Feuil2
With sh
Set m = CreateObject("Scripting.Dictionary")
For i = .Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
z = .Cells(i, 2) & .Cells(i, 3)
If Not m.Exists(z) Then m.Add z, z Else .Rows(i).Delete
Next i
End With
End Sub