1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| Sub Test()
For Ligne = 1 To 25 'nombre de ligne
For colone = 2 To 5 'Nombre de colone sur lesquels on peut écrire
If CDate(Cells(Ligne, 1)) > Date Then 'Si la date du contrôle est inférieure à la date du jour alors (1)
c = colone: If c > 2 Then c = c - 1
If Cells(Ligne, 1) <> Cells(Ligne, c) And Trim("" & Cells(Ligne, colone)) = "" Then 'Si la date de la ligne+colone = la date de la dernière colone de cette même ligne (2)
'Tolérance de 30 jour < 31
If 0 < DateDiff("d", Cells(Ligne, 1), Cells(Ligne, c)) And DateDiff("d", Cells(Ligne, 1), Cells(Ligne, c)) < 31 Then Exit For
If 0 < DateDiff("d", Cells(Ligne, 1), Cells(Ligne, c)) And DateDiff("d", Cells(Ligne, 1), Cells(Ligne, colone)) < 31 Then Exit For
'On colle la première cellule en dernière colone vide
If colone = 2 Then
Cells(Ligne, 2) = CDate(Cells(Ligne, 1))
Else
Cells(Ligne, Cells(Ligne, 1).End(xlToRight).Column + 1) = CDate(Cells(Ligne, 1))
End If
End If
If Cells(Ligne, 1) = Cells(Ligne, colone) Then Exit For
End If
Next
Next
MsgBox "Fin"
End Sub |
Partager