XL 2010 VBA - Insérer date et heures+minutes actuelle par double clics

tchi456

XLDnaute Occasionnel
Bonjour,

Bonne et heureuse année 2023!

J'ai ce code pour pouvoir insérer la date par double clics dans une cellule et je souhaiterais adapter ce code pour pouvoir y ajouter en plus l'heure+minutes actuelle en dessous de la date dans cette même cellule.

VB:
Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    ActiveSheet.Unprotect Password:="."
    If Not Intersect(Target, Range("K2")) Is Nothing Then
        Cancel = True
        If Target = "" Then
        Target.Formula = Date
        Else
        Target = ""
        End If
    End If
        ActiveSheet.Protect Password:="."
End Sub

Pouvez-vous m'aider?

Mes meilleures salutations,

Thierry
 
Solution
Bonjour @tchi456
VB:
Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    ActiveSheet.Unprotect Password:="."
    If Not Intersect(Target, Range("K2")) Is Nothing Then
        Cancel = True
        If Target = "" Then
        Target.Formula = Date & Chr(10) & Format(Time, "HH:MM")
        Else
        Target = ""
        End If
    End If
    ActiveSheet.Protect Password:="."
End Sub

Cordialement

Efgé

XLDnaute Barbatruc
Bonjour @tchi456
VB:
Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    ActiveSheet.Unprotect Password:="."
    If Not Intersect(Target, Range("K2")) Is Nothing Then
        Cancel = True
        If Target = "" Then
        Target.Formula = Date & Chr(10) & Format(Time, "HH:MM")
        Else
        Target = ""
        End If
    End If
    ActiveSheet.Protect Password:="."
End Sub

Cordialement
 

Discussions similaires

Réponses
4
Affichages
776