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
| Sub test2()
'Réf. 111025.xlsm demahom08
Dim Plage1 As Range, Plage2 As Range, c As Range, Plage3 As Range
Dim Var As Variant
With Sheets("Feuil1")
Set Plage1 = .Range(.[A1], .Cells(.Rows.Count, 1).End(xlUp)).Resize(, 2)
Plage1.Copy Sheets("Feuil3").[A1]
End With
With Sheets("Feuil2")
Set Plage2 = .Range(.[A1], .Cells(.Rows.Count, 1).End(xlUp)).Resize(, 2)
Plage2.Copy Sheets("Feuil3").Cells(.Rows.Count, 1).End(xlUp).Offset(1)
End With
With Sheets("Feuil3")
Set Plage3 = .Range(.[A1], .Cells(.Rows.Count, 1).End(xlUp)).Resize(, 2)
Plage3.RemoveDuplicates Columns:=Array(1, 2)
Set Plage3 = Plage3.Resize(, 1)
For Each c In Plage3
c.Offset(, 2).Value = Evaluate("sumproduct((Feuil1!" & Plage1.Resize(, 1).Address & "=" & c.Address & _
")*(Feuil1!" & Plage1.Resize(, 1).Offset(, 1).Address & "=" & c.Offset(, 1).Address & "),Feuil1!" & _
Plage1.Resize(, 1).Offset(, 2).Address & ")")
If c.Offset(, 2).Value = 0 Then c.Offset(, 2).Value = ""
Var = Evaluate("sumproduct((Feuil2!" & Plage2.Resize(, 1).Address & "=" & c.Address & _
")*(Feuil2!" & Plage2.Resize(, 1).Offset(, 1).Address & "=" & c.Offset(, 1).Address & "),Feuil2!" & _
Plage2.Resize(, 1).Offset(, 2).Address & ")")
If Var <> 0 Then
If c.Offset(, 2) = "" Then
c.Offset(, 2).Value = Var
Else
c.Offset(, 3).Value = Var
End If
End If
Next c
End With
End Sub |
Partager