Salut Ninos,
Salut Yvouille,
on est bien d'accord que seules les colonnes [D-E] doivent être identiques avec, en [M:M]
- "C" et un nombre positif ;
- "D" et ce même nombre négatif
Un double-clic sur la feuille '1999' démarre la macro..
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'
Dim tTab, sgRefD!, lgRefE&, lgRowD&, lgRowE1&, lgRowE2&, lgRowKC&, lgRowKD&
'
Cancel = True
With Worksheets("Extract")
.Cells.Delete
[A1].CurrentRegion.Copy Destination:=.[A1]
.Columns.AutoFit
.[A1].CurrentRegion.Sort key1:=.[M2], order1:=xlAscending, Orientation:=xlTopToBottom, Header:=xlYes
.[A1].CurrentRegion.Sort key1:=.[D2], order1:=xlAscending, key2:=.[E2], order2:=xlAscending, _
key3:=.[K2], order3:=xlAscending, Orientation:=xlTopToBottom, Header:=xlYes
tTab = .Range("A1").Resize(.UsedRange.Rows.Count + 1, .UsedRange.Columns.Count).Value
lgRowD = .Columns("K").Find(what:="C", lookat:=xlWhole, LookIn:=xlValues, searchdirection:=xlNext).Row
sgRefD = CSng(tTab(lgRowD, 4))
lgRefE = CLng(tTab(lgRowD, 5))
'
For x = lgRowD To UBound(tTab, 1)
If CSng(tTab(x, 4)) = sgRefD And CLng(tTab(x, 5)) = lgRefE Then
If tTab(x, 11) = "C" Then lgRowKC = x
If tTab(x, 11) = "D" Then lgRowKD = x
Else
If lgRowKC > 0 And lgRowKD > 0 Then
For y = lgRowD To lgRowKC
For Z = lgRowKC + 1 To lgRowKD
If tTab(Z, 1) <> "" And Abs(CDbl(tTab(Z, 13))) = CDbl(tTab(y, 13)) Then _
tTab(y, 1) = "": _
tTab(Z, 1) = "": _
Exit For
Next
Next
End If
lgRowD = x
sgRefD = CSng(tTab(x, 4))
lgRefE = CLng(tTab(x, 5))
lgRowKC = 0
lgRowKD = 0
x = lgRowD - 1
End If
Next
.[A1].Resize(UBound(tTab, 1), 1).Value = tTab
.Range("A1:A" & Range("B" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeBlanks).EntireRow.Delete shift:=xlUp
.[A1].CurrentRegion.Sort key1:=.[D2], order1:=xlAscending, key2:=.[E2], order2:=xlAscending, _
key3:=.[N2], order3:=xlAscending, Orientation:=xlTopToBottom, Header:=xlYes
.Activate
Set tTab = Nothing
End With
'
End Sub
A+