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
| Sub absent()
Dim mag, ref, ref_mag, dict, result()
Dim lig As Long, col As Long, cptMag As Long, cptRef As Long, cptMagRef As Long
Set dict = CreateObject("Scripting.Dictionary")
mag = Sheets("MAGASIN").[A1].CurrentRegion.Value
ref = Sheets("REF").[A1].CurrentRegion.Value
ref_mag = Sheets("REF_MAG").[A1].CurrentRegion.Value
For lig = 2 To UBound(ref_mag)
dict(ref_mag(lig, 1) & "_" & ref_mag(lig, 2)) = 1
Next lig
ReDim result(1 To (UBound(mag) - 1) * (UBound(ref) - 1) - dict.Count, 1 To 6)
For cptMag = 2 To UBound(mag)
For cptRef = 2 To UBound(ref)
If Not dict.exists(mag(cptMag, 1) & "_" & ref(cptRef, 1)) Then
cptMagRef = cptMagRef + 1
result(cptMagRef, 1) = mag(cptMag, 1)
For col = 2 To 4
result(cptMagRef, col) = mag(cptMag, col + 1)
Next col
result(cptMagRef, 5) = mag(cptMag, 2)
result(cptMagRef, 6) = ref(cptRef, 1)
End If
Next cptRef
Next cptMag
Sheets("RESULTAT").[A2].Resize(UBound(result, 1), UBound(result, 2)) = result
Set dict = Nothing
End Sub |
Partager