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
| Sub Correspondances()
Dim LastLig As Long, i As Long, Cpt As Long, Ind As Long
Dim c As Range
Dim Ap As String
Application.ScreenUpdating = False
'On copie la feuille initiale
Feuil1.Copy After:=Feuil1
With ActiveSheet
LastLig = .Cells(.Rows.Count, 1).End(xlUp).Row
Application.DisplayAlerts = False
'on scinde la colonne Identifiant en 25
.Columns("F:F").Insert
.Range("E2:E" & LastLig).TextToColumns Destination:=.Range("E2"), DataType:=xlDelimited, Space:=True, FieldInfo:=Array(Array(1, 2), Array(2, 2))
.Columns("I:J").Insert
'et la colonne Technologie en 3
.Range("H2:H" & LastLig).TextToColumns Destination:=.Range("H2"), DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array(1, 1))
.Range("I2:I" & LastLig).TextToColumns Destination:=.Range("I2"), DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array(1, 1))
Application.DisplayAlerts = True
'on concatène en L le suivant,le type et l'id suivant
'et en M le précédent, le type et l'id précédent
With .Range("L2:L" & LastLig)
.Formula = "=J2&F2"
.Value = .Value
End With
With .Range("M2:M" & LastLig)
.Formula = "=I2&E2"
.Value = .Value
End With
'on parcoure les colonnes L et I pour indiquer en N les correspondances
For i = 2 To LastLig
If .Range("N" & i) = "" Then
Set c = .Range("M2:M" & LastLig).Find(.Range("L" & i), LookAt:=xlWhole)
If Not c Is Nothing Then
If c.Offset(, 1) <> "" Then
Ind = c.Offset(, 1)
Else
Cpt = Cpt + 1
Ind = Cpt
End If
.Range("N" & i) = Format(Ind, "0000.000")
c.Offset(, 1) = Format(Ind * 1.01, "0000.000")
End If
End If
Next i
.Range("A2:N" & LastLig).NumberFormat = "0"
.Range("A2:N" & LastLig).Sort Key1:=.Range("N2"), Header:=xlNo
End With
End Sub |