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 55 56
| Sub test()
Dim sh As Worksheet, TablX As Variant, TablY As Variant, Plage As Range, C As Range, Result()
Dim Ctr As Long, Teste As Boolean, I As Long, J As Long, K As Long
With Workbooks("x.xlsm").Sheets("Jalons")
Set Plage = .Range("A1", .Cells(.Rows.Count, 1).End(xlUp)).Resize(, 3)
Plage.Resize(, 1).Offset(, 3).Formula = "=row()"
ReDim Result(Plage.Rows.Count - 1, 1)
End With
With ThisWorkbook.Sheets(1)
.Cells.ClearContents
Plage.Copy
ThisWorkbook.Sheets(1).[A1].PasteSpecial xlPasteValues
Set Plage = .Range("A1", .Cells(.Rows.Count, 1).End(xlUp)).Resize(, 4)
Plage.Resize(, 1).Offset(, 3).Formula = "=row()"
Plage.Value = Plage.Value
Plage.Sort .[A1], xlAscending, .[B1], , xlAscending, .[C1], xlAscending, Header = xlNo
TablX = Plage
End With
With Workbooks("y.xlsm").Sheets(1)
Set Plage = .Range("A1", .Cells(.Rows.Count, 1).End(xlUp)).Resize(, 3)
Plage.Resize(, 1).Offset(, 3).Formula = "=row()"
End With
With ThisWorkbook.Sheets(1)
.Cells.ClearContents
Plage.Copy
ThisWorkbook.Sheets(1).[A1].PasteSpecial xlPasteValues
Set Plage = .Range("A1", .Cells(.Rows.Count, 1).End(xlUp)).Resize(, 4)
Plage.Resize(, 1).Offset(, 3).Formula = "=row()"
Plage.Value = Plage.Value
Plage.Sort .[A1], xlAscending, .[B1], , xlAscending, .[C1], xlAscending, Header = xlNo
TablY = Plage
Ctr = -1
K = 1
For I = 1 To UBound(TablX, 1)
Teste = False
' If TablX(i, 1) = 15 Then Stop
For J = K To UBound(TablY, 1)
If TablX(I, 1) = TablY(J, 1) And TablX(I, 2) = TablY(J, 2) And TablX(I, 3) = TablY(J, 3) Then
Ctr = Ctr + 1
Result(Ctr, 0) = TablX(I, 4)
Result(Ctr, 1) = TablY(J, 4)
Teste = True
K = I
Exit For
End If
Next J
If Teste = False Then
Ctr = Ctr + 1
Result(Ctr, 0) = TablX(I, 4)
Result(Ctr, 1) = "?"
End If
Next I
.Cells.ClearContents
.[A1].Resize(UBound(TablX, 1) + 1, 2) = Result
End With
End Sub |
Partager