XL 2019 Modifier ce code pour de sorte à y rajouter un commentaire après clic droit en colonne I (9) à préremplir mais vierge ?

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

anthoYS

XLDnaute Barbatruc
Bonjour


VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.Column = 1 And Target.Row > 1 Then
    Cancel = True
    Ligne = Target.Row 'ou Application.Goto [repas].Columns(1).Find(Date)

    UserForm1.Show
    End If
End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
  If Target.Column = 2 Then ' Vérifie si le clic droit est dans la colonne B
    Cancel = True ' Annule le menu contextuel par défaut
    'Masque les commentaires
    Application.DisplayCommentIndicator = xlCommentIndicatorOnly

    ' Crée ou ouvre une nouvelle note
    If Target.Comment Is Nothing Then
      Range("A1").Copy
      With Target
        .PasteSpecial Paste:=xlPasteComments
        .Comment.Visible = True
        .Comment.Shape.Select
      End With
    End If
  End If
End Sub


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    'Masque les commentaires
    Application.DisplayCommentIndicator = xlCommentIndicatorOnly
End Sub

Merci :=)
 
Solution
VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.Column = 1 And Target.Row > 1 Then
        Cancel = True
        Ligne = Target.Row 'ou Application.Goto [repas].Columns(1).Find(Date)
        UserForm1.Show
    End If
End Sub

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    If Target.Column = 2 Then ' Vérifie si le clic droit est dans la colonne B
        Cancel = True ' Annule le menu contextuel par défaut
        Application.DisplayCommentIndicator = xlCommentIndicatorOnly
        ' Crée ou ouvre une nouvelle note avec du texte présaisi, espacé, en gras et souligné
        If Target.Comment Is Nothing Then
            With Target...
Bonjour
Un fichier aurai été le bienvenu...
VB:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
  If Target.Column = 2 Then ' Vérifie si le clic droit est dans la colonne B
    Cancel = True ' Annule le menu contextuel par défaut
    'Masque les commentaires
    Application.DisplayCommentIndicator = xlCommentIndicatorOnly
    ' Crée ou ouvre une nouvelle note
    If Target.Comment Is Nothing Then
      Range("A1").Copy
      With Target
        .PasteSpecial Paste:=xlPasteComments
        .Comment.Visible = True
        .Comment.Shape.Select
      End With
    End If
  elseif target.column=9 then
    Cancel = True ' Annule le menu contextuel par défaut
    'Masque les commentaires
    Application.DisplayCommentIndicator = xlCommentIndicatorOnly
    ' Crée ou ouvre une nouvelle note
    If Target.Comment Is Nothing Then
      Range("A1").Copy
      With Target
        .PasteSpecial Paste:=xlPasteComments
        .Comment.Visible = True
        .Comment.Shape.Select
      End With
    End If 
  End If
End Sub
A+ François
 
Bonjour
Un fichier aurai été le bienvenu...
VB:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
  If Target.Column = 2 Then ' Vérifie si le clic droit est dans la colonne B
    Cancel = True ' Annule le menu contextuel par défaut
    'Masque les commentaires
    Application.DisplayCommentIndicator = xlCommentIndicatorOnly
    ' Crée ou ouvre une nouvelle note
    If Target.Comment Is Nothing Then
      Range("A1").Copy
      With Target
        .PasteSpecial Paste:=xlPasteComments
        .Comment.Visible = True
        .Comment.Shape.Select
      End With
    End If
  elseif target.column=9 then
    Cancel = True ' Annule le menu contextuel par défaut
    'Masque les commentaires
    Application.DisplayCommentIndicator = xlCommentIndicatorOnly
    ' Crée ou ouvre une nouvelle note
    If Target.Comment Is Nothing Then
      Range("A1").Copy
      With Target
        .PasteSpecial Paste:=xlPasteComments
        .Comment.Visible = True
        .Comment.Shape.Select
      End With
    End If
  End If
End Sub
A+ François

Merci, par contre le commentaire reste le même, or en colonne 9 je veux qu'il soit vide, et je ne veux pas non plus qu'il reste affiché.

Mais faire comment avant si cela est possible.
 
pour info,

je joins la solution :
VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.Column = 1 And Target.Row > 1 Then
        Cancel = True
        Ligne = Target.Row 'ou Application.Goto [repas].Columns(1).Find(Date)
        UserForm1.Show
    End If
End Sub

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    If Target.Column = 2 Then ' Vérifie si le clic droit est dans la colonne B
        Cancel = True ' Annule le menu contextuel par défaut
        ' Masque les commentaires
        Application.DisplayCommentIndicator = xlCommentIndicatorOnly
        ' Crée ou ouvre une nouvelle note avec du texte présaisi
        If Target.Comment Is Nothing Then
            With Target
                .AddComment "petit déj : " & vbNewLine & "déj : " & vbNewLine & "snack/collation : " & vbNewLine & "diner : "
                .Comment.Visible = True
                .Comment.Shape.Select
            End With
        Else
            Target.Comment.Visible = True
            Target.Comment.Shape.Select
        End If
    ElseIf Target.Column = 9 Then ' Vérifie si le clic droit est dans la colonne I
        Cancel = True ' Annule le menu contextuel par défaut
        ' Masque les commentaires
        Application.DisplayCommentIndicator = xlCommentIndicatorOnly
        ' Crée ou ouvre une nouvelle note vierge
        If Target.Comment Is Nothing Then
            With Target
                .AddComment ""
                .Comment.Visible = True
                .Comment.Shape.Select
            End With
        Else
            Target.Comment.Visible = True
            Target.Comment.Shape.Select
        End If
    End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    ' Masque les commentaires
    Application.DisplayCommentIndicator = xlCommentIndicatorOnly
End Sub


Bonne journée !
 
L'objectif, serait d'avoir ça en B (colonne 2) :
firefox_0xj2nd13Id.png
 
VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.Column = 1 And Target.Row > 1 Then
        Cancel = True
        Ligne = Target.Row 'ou Application.Goto [repas].Columns(1).Find(Date)
        UserForm1.Show
    End If
End Sub

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    If Target.Column = 2 Then ' Vérifie si le clic droit est dans la colonne B
        Cancel = True ' Annule le menu contextuel par défaut
        Application.DisplayCommentIndicator = xlCommentIndicatorOnly
        ' Crée ou ouvre une nouvelle note avec du texte présaisi, espacé, en gras et souligné
        If Target.Comment Is Nothing Then
            With Target
                .AddComment ""
                With .Comment.Shape.TextFrame.Characters
                    .Text = "petit déj : " & vbNewLine & vbNewLine & "déj : " & vbNewLine & vbNewLine & "snack/collation : " & vbNewLine & vbNewLine & "diner : "
                    .Font.Bold = True
                    .Font.Underline = True
                End With
                ' Agrandit la fenêtre du commentaire
                .Comment.Shape.Width = 200 ' Largeur en points
                .Comment.Shape.Height = 150 ' Hauteur en points
                .Comment.Visible = True
                .Comment.Shape.Select
            End With
        Else
            Target.Comment.Visible = True
            Target.Comment.Shape.Select
        End If
    ElseIf Target.Column = 9 Then ' Vérifie si le clic droit est dans la colonne I
        Cancel = True ' Annule le menu contextuel par défaut
        Application.DisplayCommentIndicator = xlCommentIndicatorOnly
        ' Crée ou ouvre une nouvelle note vierge
        If Target.Comment Is Nothing Then
            With Target
                .AddComment ""
                .Comment.Visible = True
                .Comment.Shape.Select
            End With
        Else
            Target.Comment.Visible = True
            Target.Comment.Shape.Select
        End If
    End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Application.DisplayCommentIndicator = xlCommentIndicatorOnly
End Sub
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
4
Affichages
423
Réponses
3
Affichages
578
Retour