Bonjour
Et lorsque que je mets pas la date d'aujourd'hui le code ne marche pas
Je ne sais pas ce que vous faites avec votre fichier mais en B1 vous avez bien le 04/01/2022 ?
Le code recherche la date du jour
Edit : j'ai modifié les deux codes en fonction du fait que vous commencez le lundi en B1 (donc ici comme janvier B1 = 04/01/2022
Code ouverture
Private Sub Workbook_Open()
Dim lig As Integer, dlg As Integer
Dim Plage As Range, c As Range
With Sheets(1)
lig = 5
Set Plage = .Range(.Cells(1, 2), .Cells(1, .Cells(1, Columns.Count).End(xlToLeft).Column))
For Each c In Plage
If CDate(c.Value) = Format(Date, "short date") Then
dlg = Cells(Rows.Count, c.Column + 1).End(xlUp).Row
If dlg < 5 Then lig = 5 Else: lig = dlg + 1
.Cells(lig, c.Column + 1) = Format(Now, "hh:mm:ss")
End If
Next c
End With
End Sub
code de fermeture
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim lig As Integer, dlg As Integer
Dim Plage As Range, c As Range
With Sheets(1)
lig = 5
'dlg = Range("B" & Rows.Count).End(xlUp).Row
'If dlg < 5 Then lig = 5 Else: lig = dlg + 1
Set Plage = .Range(.Cells(1, 2), .Cells(1, .Cells(1, Columns.Count).End(xlToLeft).Column))
For Each c In Plage
If CDate(c.Value) = Format(Date, "short date") Then
dlg = Cells(Rows.Count, c.Column).End(xlUp).Row
If dlg < 5 Then lig = 5 Else: lig = dlg + 1
.Cells(lig, c.Column) = Format(Now, "hh:mm:ss")
End If
Next c
End With
With ThisWorkbook
Application.DisplayAlerts = False
.Save
End With
End Sub