Bonsoir à tous,
A tester :
En fait la feuille "kms" est le miroir de la feuille "Aller" que tu devrais appeler "horaires", ça serait plus judicieux.
Option Explicit
Sub test()
Dim a, x, y, i As Long, lig As Long, col As Byte, derLig As Long, derCol As Byte
Dim dico As Object
Set dico = CreateObject("Scripting.Dictionary")
dico.CompareMode = 1
a = Sheets("grille kms").Cells(1).CurrentRegion.Value
With Sheets("Aller")
derLig = .Cells(.Rows.Count, 2).End(xlUp).Row
derCol = .Cells(8, .Columns.Count).End(xlToLeft).Column
For col = 4 To derCol
For lig = 8 To derLig
If .Cells(lig, col).Value <> "-" Then
If dico.Count = 0 Then
dico(.Cells(lig, 2).Value) = 0
Else
dico(.Cells(lig, 2).Value) = Empty
End If
End If
Next
For i = 1 To dico.Count - 1
x = Application.Match(dico.keys()(i - 1), Application.Index(a, 0, 1), 0)
y = Application.Match(dico.keys()(i), Application.Index(a, 2, 0), 0)
dico.Item(dico.keys()(i)) = a(x, y)
Next
With Sheets("kms")
For lig = 8 To derLig
If dico.exists(.Cells(lig, 2).Value) Then
.Cells(lig, col).Value = dico(.Cells(lig, 2).Value)
Else
.Cells(lig, col).Value = "-"
End If
Next
End With
dico.RemoveAll
Next
End With
Set dico = Nothing
End Sub
klin89