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 63
| Option Explicit
Private Sub CommandButton1_Click()
Dim LastLig As Long, i As Long
Dim cel As Range, c As Range, r As Range
Dim kod As Collection, moi As Collection, tran As Collection
Application.ScreenUpdating = False
With Sheets("Feuil1")
'Ajout d'une colonne Date & Dossier & Mode transp
LastLig = .Range("A65536").End(xlUp).Row
For i = 2 To LastLig
.Range("L" & i).Value = .Range("A" & i).Value & .Range("I" & i).Value & .Range("H" & i).Value
Next i
Set kod = New Collection 'Valeurs sans doublons de la nouvelle colonne
On Error Resume Next
For Each cel In .Range("L2:L" & LastLig)
If cel <> "" Then kod.Add cel, CStr(cel)
Next cel
On Error GoTo 0
Set moi = New Collection 'Valeurs sans doublons des dates (mois)
On Error Resume Next
For Each cel In .Range("A2:A" & LastLig)
If cel <> "" Then moi.Add cel, CStr(cel)
Next cel
On Error GoTo 0
Set tran = New Collection 'Valeurs sans doublons des modes de transport
On Error Resume Next
For Each cel In .Range("H2:H" & LastLig)
If cel <> "" Then tran.Add cel, CStr(cel)
Next cel
On Error GoTo 0
End With
With Sheets("Feuil2")
.Cells.ClearContents
For i = 1 To moi.Count 'Titres de lignes
.Cells(i + 1, 1).Value = CDate(moi.Item(i))
Next i
For i = 1 To tran.Count 'Titres de colonnes
.Cells(1, i + 1).Value = tran.Item(i)
Next i
For i = 1 To kod.Count 'Intersection
Set c = .Range("A2:A" & .Range("A65536").End(xlUp).Row).Find(CDate(Left(kod.Item(i), 10)), LookIn:=xlValues, LookAt:=xlWhole)
If Not c Is Nothing Then
Set r = .Range(.Cells(1, 2), .Cells(1, .Range("IV1").End(xlToRight).Column)).Find(Mid(kod.Item(i), 21, Len(kod.Item(i)) - 20), LookIn:=xlValues, LookAt:=xlWhole)
If Not r Is Nothing Then .Cells(c.Row, r.Column) = .Cells(c.Row, r.Column) + 1
End If
Set c = Nothing: Set r = Nothing
Next i
End With
Set kod = Nothing
Set moi = Nothing
Set tran = Nothing
Sheets("Feuil1").Columns("L:L").ClearContents
Application.ScreenUpdating = True
End Sub |
Partager