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 57 58 59 60 61 62
| Option Explicit
Dim f1 As Worksheet, f2 As Worksheet
Dim DerLig_f1 As Long, i As Long, j As Long, Col_f2 As Long, Lig_f2 As Long, DerCol_f1 As Long
Sub Separation()
Dim Noms
Application.ScreenUpdating = False
Set f1 = Sheets("Feuille 1")
Set f2 = Sheets("Resultats")
DerLig_f1 = f1.Range("A" & Rows.Count).End(xlUp).Row
DerCol_f1 = f1.Range("C6").End(xlToRight).Column
f2.Cells.ClearContents
f1.Cells.Replace What:=",", Replacement:=")"
f1.Cells.Replace What:="/", Replacement:=")"
f1.Cells.Replace What:="))", Replacement:=")"
Lig_f2 = 1
For i = 7 To DerLig_f1 Step 2
Col_f2 = 1
For j = 3 To DerCol_f1
On Error Resume Next
Noms = Split(f1.Cells(i, j), ")")
If Err.Number = 0 Then
f2.Cells(Lig_f2, Col_f2).Resize(UBound(Noms) + 1).Value = Application.Transpose(Noms)
On Error GoTo 0
End If
Col_f2 = Col_f2 + 1
Next j
Lig_f2 = f2.Range("A1").CurrentRegion.Rows.Count + 1
Next i
f2.Select
Tri_Suppr_Doublons
With f2.Cells
.WrapText = False
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlTop
.EntireColumn.AutoFit
.EntireRow.AutoFit
.WrapText = True
End With
Set f1 = Nothing
Set f2 = Nothing
End Sub
Sub Tri_Suppr_Doublons()
Application.DisplayAlerts = False
For i = 1 To Lig_f2
For j = 1 To DerCol_f1 - 2
f2.Cells(i, j) = LTrim(f2.Cells(i, j))
Next j
Next i
For i = 1 To DerCol_f1 - 2
ActiveWorkbook.Worksheets("Resultats").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Resultats").Sort.SortFields.Add2 Key:=Range(f2.Cells(1, i), f2.Cells(Lig_f2, i)), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Resultats").Sort
.SetRange Range(f2.Cells(1, i), f2.Cells(Lig_f2, i))
.Header = xlNo
.SortMethod = xlPinYin
.Apply
End With
Range(f2.Cells(1, i), f2.Cells(Lig_f2, i)).RemoveDuplicates Columns:=1, Header:=xlNo
Next i
End Sub |
Partager