Bonjour
Dans votre fichier faites ceci :
1. Onglet Bilan
- Click droite puis choisir "Visualiser le code"
- Dans la fenetre, coller le code ci-dessous
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B3")) Is Nothing Then
Fruit = Target.Value
Call BilanFruit
End If
End Sub
2. Allez dans l'éditeur VBA
- dans le menu choisir insertion choisir -> Module
- Dans la fenetre, coller le code ci-dessous
Public Fruit As String
Sub BilanFruit()
Dim c As Range, Plage As Range
Dim tablo As Collection
Dim item
Dim dlgB As Integer
With Sheets("Tableau des ventes")
Set Plage = .Range("B4:B" & .Range("B" & Rows.Count).End(xlUp).Row)
Set tablo = New Collection
On Error Resume Next
For Each c In Plage
If .Range("E" & c.Row) = Fruit Then
tablo.Add c.Value, CStr(c.Value)
End If
Next c
End With
On Error GoTo 0
With Sheets("Bilan")
.Range("A6").CurrentRegion.Offset(1, 0).Delete
For Each item In tablo
dlgB = .Range("A" & Rows.Count).End(xlUp).Row + 1
.Range("A" & dlgB) = item
.Range("B" & dlgB) = WorksheetFunction.SumIfs(Plage.Offset(0, 1), Plage, item, Plage.Offset(0, 3), Fruit)
.Range("C" & dlgB) = WorksheetFunction.SumIfs(Plage.Offset(0, 2), Plage, item, Plage.Offset(0, 3), Fruit)
Next item
End With
End Sub
3. Enregistrez votre fichier au format XLSM pour accepter l'utilisation des macros
Une fois terminé, changez la valeur en B3 dans la feuille Bilan
Cordialement