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
| Sub ILIES()
Dim ShGr As Worksheet
Dim Arr, Brr, x
Dim plage1 As Range, plage2 As Range, plage3 As Range, plage4 As Range, plage5 As Range
Set ShGr = ThisWorkbook.Worksheets("GrandLivre")
LignB = ShGr.Cells(ShGr.Rows.Count, 1).End(xlUp).Row
Set plage1 = ShGr.Range("H2:H" & LignB)
Set plage2 = ShGr.Range("D2:D" & LignB)
'====================================================================================
ShGr.Range("A2:F" & LignB).Copy
ShGr.Range("L2:Q" & LignB).PasteSpecial
ShGr.Range("L2:Q" & LignB).RemoveDuplicates Columns:=4, Header:=xlYes
'=====================================================================================
LignC = ShGr.Cells(ShGr.Rows.Count, 12).End(xlUp).Row
Brr = ShGr.Range("L3:R" & LignC)
For i = LBound(Brr) To UBound(Brr)
If Brr(i, 6) Like "*-C_*" Then
x = Split(Brr(i, 6), "_")
Brr(i, 7) = x(1) & "_" & Replace(x(0), "-C", "") & "_" & Application.WorksheetFunction.SumIf(plage2, x(1), plage1)
Else
Brr(i, 7) = Format(Brr(i, 4), "0000000") & "_" & Split(Brr(i, 6), "-")(0) & "_" & Application.WorksheetFunction.SumIf(plage2, Brr(i, 4), plage1)
End If
Next i
ShGr.Range("L3:R" & LignC) = Brr
'=======================================================================================
Set mondico = CreateObject("Scripting.Dictionary")
For Each c In ShGr.Range("R3", [R65000].End(xlUp))
If c <> "" Then mondico.Item(c.Value) = mondico.Item(c.Value) + 1
Next c
'========================================================================================
ShGr.Columns("J:J").NumberFormat = "General"
ShGr.Range("J2").Value = "N°PIECE"
i = 3
For Each c In ShGr.Range("R3", [R65000].End(xlUp))
If mondico.Item(c.Value) > 1 Then
'c.Interior.ColorIndex = 4
ShGr.Range("J" & i) = c.Offset(0, -3)
i = i + 1
End If
Next c
'==========================================================================================
If ShGr.Range("J2").Value <> "" Then
ShGr.Range("A2:H" & LignB).AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=ShGr.Range("J2").CurrentRegion, Unique:=False
ShGr.Range("_FilterDataBase").Offset(1, 0).Resize(Range("_FilterDataBase").Rows.Count - 1).SpecialCells(xlCellTypeVisible).Delete Shift:=xlUp
ShGr.ShowAllData
End If
ShGr.Columns("I:U").ClearContents
End Sub |
Partager