Sub Transfert_mois()
Dim décal%, mois%, f As Worksheet, taille&, i%, ecart As Range, P As Range, c1 As Range, c2 As Range
décal = 2
[A1].CurrentRegion.Name = "zone" 'plage nommée
mois = Month(Range("zone").Item(2, 3))
Set f = Sheets(1)
taille = f.Range("A" & f.Rows.Count).End(xlUp).Row - 1
If taille = 0 Then Exit Sub
For i = 0 To 5
With f.Cells(2, mois + décal).Resize(taille).Offset(, 13 * i)
.Formula = "=vlookup(A2,zone," & 4 + i & ",false)"
.Value = .Value 'supprime les formules
Set ecart = .Offset(, 13 - mois)
Set P = .Offset(, 1 - mois).Resize(, 12) 'plage de 12 mois
Set c1 = P.Find("*", , xlValues, , xlByColumns, xlPrevious)
If c1 Is Nothing Then
ecart.ClearContents
ElseIf c1.Column = P.Column Then
ecart.ClearContents
Else
Set c2 = P.Find("*", f.Cells(2, c1.Column), xlValues, , xlByColumns, xlPrevious)
If c2.Column = c1.Column Then
ecart.ClearContents
Else
ecart = "=" & f.Cells(2, c1.Column).Address(0, 0) & "-" & f.Cells(2, c2.Column).Address(0, 0)
ecart = ecart.Value 'supprime les formules
End If
End If
End With
Next
End Sub