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
| Sub Test_Boucle_Groupement()
Dim PreLigCommande As Long, DerLigCommande As Long, LigFinBase As Long
Dim Ncom As Integer, NbA As Integer, NbB As Integer, NbC As Integer
Dim PlageCdes As Range, PlageCommande As Range
Set WsBase = Worksheets("Base")
LigFinBase = WsBase.[G65536].End(xlUp).Row
Set PlageCdes = WsBase.Range("G2:G" & LigFinBase)
For PreLigCommande = 2 To LigFinBase
Ncom = Cells(PreLigCommande, 7).Value
NbA = 0
NbB = 0
NbC = 0
Set trouve = PlageCdes.Find(Ncom, PlageCdes.Cells(PlageCdes.Count), xlValues, xlWhole, xlByColumns, xlPrevious)
If Not trouve Is Nothing Then
DerLigCommande = trouve.Row
Set PlageCommande = WsBase.Range("K" & PreLigCommande & ":K" & DerLigCommande)
For Each c In PlageCommande
Select Case c.Value
Case Is = "A"
NbA = NbA + Cells(c.Row, 13).Value
Case Is = "B"
NbB = NbB + Cells(c.Row, 13).Value
Case Is = "C"
NbC = NbC + Cells(c.Row, 13).Value
End Select
Next c
MsgBox ("Commande n° " & Ncom & Chr(10) & "Il y a " & NbA & " A commandés" & Chr(10) & "Il y a " & NbB & " B commandés." & Chr(10) & "Il y a " & NbC & " C commandés.")
PreLigCommande = DerLigCommande
End If
Next PreLigCommande
End Sub |
Partager