commentaire avec la date si la valeur de la cellule change

pascal21

XLDnaute Barbatruc
bonsoir à tous
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Target.ClearComments
 If Target.Comment Is Nothing Then
    Target.AddComment
    Target.Comment.Text Text:=CStr(Date) & Chr(10)
    lg = Len(Target.Comment.Text)
    With Target.Comment.Shape.TextFrame
      .Characters(Start:=1, Length:=lg).Font.Name = "Verdana"
      .Characters(Start:=1, Length:=lg).Font.Size = 8
      .Characters(Start:=1, Length:=lg).Font.Bold = True
      .Characters(Start:=1, Length:=lg).Font.Italic = True
      .Characters(Start:=1, Length:=lg).Font.ColorIndex = 3
      .Characters(Start:=lg, Length:=99).Font.Bold = False
      .Characters(Start:=lg, Length:=99).Font.Italic = False
      .Characters(Start:=lg, Length:=99).Font.ColorIndex = 1
    End With
    SendKeys "m"
  Else
    SendKeys "m"
  End If
End Sub
j'utilise ce code pour inscrire la date dans une cellule sur un double clic
ça fonctionne mais je ne suis pas entierement satisfait
j'aimerais que le commentaire se créer au changement de valeur des celulles des colonnes O P S T uniquement
les essais que j'ai tenté se sont revélés infructueux
pouvez-vous m'aider,
merci
 

Habitude

XLDnaute Accro
Re : commentaire avec la date si la valeur de la cellule change

Code:
Const O = 15, P = 16, S = 19, T = 20

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Target.ClearComments
Dim colonne As Integer
colonne = Target.Column
 
If colonne = O Or colonne = P Or colonne = S Or colonne = T Then
    If Target.Comment Is Nothing Then
       Target.AddComment
       Target.Comment.Text Text:=CStr(Date) & Chr(10)
       lg = Len(Target.Comment.Text)
       With Target.Comment.Shape.TextFrame
         .Characters(Start:=1, Length:=lg).Font.Name = "Verdana"
         .Characters(Start:=1, Length:=lg).Font.Size = 8
         .Characters(Start:=1, Length:=lg).Font.Bold = True
         .Characters(Start:=1, Length:=lg).Font.Italic = True
         .Characters(Start:=1, Length:=lg).Font.ColorIndex = 3
         .Characters(Start:=lg, Length:=99).Font.Bold = False
         .Characters(Start:=lg, Length:=99).Font.Italic = False
         .Characters(Start:=lg, Length:=99).Font.ColorIndex = 1
       End With
       SendKeys "m"
     Else
       SendKeys "m"
     End If
End If
End Sub
 

Discussions similaires

Statistiques des forums

Discussions
312 335
Messages
2 087 386
Membres
103 530
dernier inscrit
dieubrice