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
| Option Explicit
Sub Test()
Dim Ws As Worksheet
Dim C As Range, Cel As Range
Set Ws = Worksheets("REC")
'On recherche la colonne avec l'en-tête "DCK" dans la feuille "DCE"
Set C = Worksheets("DCE").Rows(1).Find("DCK", LookIn:=xlValues)
'Si l'en-tête a été trouvée, la colonne "DCK" est copiee dans la colonne "A" dela feuille "REC"
If Not C Is Nothing Then C.EntireColumn.Copy Destination:=Ws.Columns(1)
'On recherche la colonne avec l'en-tête "AFK" dans la feuille "AFE"
Set C = Worksheets("AFE").Rows(1).Find("AFK", LookIn:=xlValues)
'Si l'en-tête a été trouvée, la colonne "AFK" est copiee dans la colonne "D" de la feuille "REC"
If Not C Is Nothing Then C.EntireColumn.Copy Destination:=Ws.Columns(4)
'une colonne intitulee "AFM" est creee dans la colonne "B"
Ws.Range("B1") = "AFM"
'une colonne intitulee "DCM" est creee dans la colonne "E"
Ws.Range("E1") = "DCM"
'Dans la feuille "REC", pour chaque cellule remplie de la colonne "DCK", on recherche la ligne dont le texte de la cellule _
est identique de la colonne "AFK" et on recopie le numero de la ligne de la colonne "AFK" dans la colonne "AFM", _
sinon on inscrit "NOK".
Cherche Ws, 1, 4
'Dans la feuille "REC", pour chaque cellule remplie de la colonne "AFK", on recherche la ligne dont le texte de la cellule _
est identique de la colonne "DCK" et on recopie le numero de la ligne de la colonne "DCK" dans la colonne "DCM", _
sinon on inscrit "NOK".
Cherche Ws, 4, 1
End Sub
Sub Cherche(Sh As Worksheet, ColSource As Integer, ColCible As Integer)
Dim DerLig As Long
Dim firstAddress As String
Dim C As Range, Cel As Range
DerLig = Sh.Cells(Sh.Rows.Count, ColSource).End(xlUp).Row
For Each Cel In Sh.Range(Sh.Cells(2, ColSource), Sh.Cells(DerLig, ColSource))
If Cel <> "" Then
Set C = Sh.Columns(ColCible).Find(Cel, LookIn:=xlValues, lookat:=xlWhole)
If Not C Is Nothing Then
firstAddress = C.Address
Do
Cel.Offset(0, 1) = C.Row
Set C = Sh.Columns(ColCible).FindNext(C)
Loop While Not C Is Nothing And C.Address <> firstAddress
Else
Cel.Offset(0, 1) = "NOK"
End If
End If
Next Cel
End Sub |
Partager