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 test()
Dim Sh1 As Worksheet, Sh2 As Worksheet, Plage As Range, C As Range
Dim Ligne As Long, Plage2 As Range, X As Range
Ligne = 1
Set Sh1 = Workbooks("Fichier 1.xlsx").Sheets("Feuil1")
Set Sh2 = Workbooks("Source.xlsx").Sheets("Feuil1")
With Sh1
Set Plage = .Range(.[A2], .Cells(.Rows.Count, 1).End(xlUp))
End With
With Sh2
Set Plage2 = .Range(.[B2], .Cells(.Rows.Count, 2).End(xlUp))
End With
With ThisWorkbook.Sheets("Feuil1")
.[A1:C1].Value = Array("Index", "Nom", "Valeurs")
For Each C In Plage
For Each X In Plage2
If InStr(1, X.Value, C.Value) = 1 Then
Ligne = Ligne + 1
.Cells(Ligne, 1).Value = X.Offset(, -1).Value
.Cells(Ligne, 2).Value = X.Value
lig = Application.Match(X.Value, Sh2.[B:B], 0)
.Cells(Ligne, 3).Value = Application.Index(Sh2.[A:A], lig, 1)
Exit For
End If
Next X
Next C
End With
End Sub |
Partager