Touche delete

Bonjour j'aimerai tester si la touche delete a été pressée dans ce module, merci

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Target.Select
x = ActiveCell.Row
y = ActiveCell.Column

ICI TEST SI LA TOUCHE DELETE A ETE PRESSEE

Application.EnableEvents = False
If Not Intersect(Target, Cells(x, y)) Is Nothing Then
       If Now() >= Range("b2") And Now() <= Range("b3") Then
          Cells(x + 39, y) = ActiveCell.Value
          Cells(x, y).AddComment
          Cells(x, y).Comment.Visible = False
          Cells(x, y).Comment.Text Text:="1er semèstre"
       End If
       If Now() >= Range("b5") And Now() <= Range("b6") Then
          Cells(x + 66, y) = ActiveCell.Value
          Cells(x, y).AddComment
          Cells(x, y).Comment.Visible = False
          Cells(x, y).Comment.Text Text:="2ème semèstre"
       End If
End If
Target.Select
Application.EnableEvents = True
End Sub

Tu ne peux pas detecter un évènement d'une touche.

En effet quand tu cliques sur une cellule elle passe en édit mode. Et ne quite l'édit mode que quand tu en sors... Les deux evenements peuvent déclancher des macros mais au milieu aucune macro n'est déclanchée.

Application.onkey

Solution de contournement lancer une macro toutes les secondes avec une onkey.. Mais cela ralentirait beaucoup ton classeur...

Plutôt que de detecter le keypress detecte si la value est différente de vide..

est ce que je peux le faire dans une autre procédure, par exemple dans la sub change de la feuille? et comment le faire? merci

La question est que veux tu faire..

je vous met le fichier joint, j'aimerais que quand on efface une note dans le tableau du haut elle puisse s'effacer et quelle s'efface aussi dans les tableaux du bas, merci

Il suffira de faire un truc du genre

On Error Resume Next

If Target.Value = "" Then

Range(x, y).Offset(39, 0).Value = ""

End If

par contre les cellules fusionnées... C'est pas une bonne idée et tu vas galérer ...

merci, ca marche, par contre j'aimerais aussi en meme temps effacer le commentaire?

target.comment.delete

ca ne marche pas? voici le code modifié

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Target.Select
x = ActiveCell.Row
y = ActiveCell.Column

Application.EnableEvents = False

If Not Intersect(Target, Cells(x, y)) Is Nothing Then
       If Now() >= Range("b2") And Now() <= Range("b3") Then
          On Error Resume Next
          If Target.Value = "" Then
             Target.Comment.Delete
             Range(x, y).Offset(39, 0).Value = ""
          End If
          Cells(x + 39, y) = ActiveCell.Value
          Cells(x, y).AddComment
          Cells(x, y).Comment.Visible = False
          Cells(x, y).Comment.Text Text:="1er semèstre"
       End If
       If Now() >= Range("b5") And Now() <= Range("b6") Then
       On Error Resume Next
       If Target.Value = "" Then
         Cells(x, y).Selection.ClearComments
         Range(x, y).Offset(66, 0).Value = ""
       End If
          Cells(x + 66, y) = ActiveCell.Value
          Cells(x, y).AddComment
          Cells(x, y).Comment.Visible = False
          Cells(x, y).Comment.Text Text:="2ème semèstre"
       End If
End If
Target.Select
Application.EnableEvents = True
End Sub

range(x,y).comment.delete

merci de votre disponibilité et j'ai modifié le code et maintenant ca marche, merci encore et à bientot

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Target.Select
x = ActiveCell.Row
y = ActiveCell.Column
Application.EnableEvents = False
If Not Intersect(Target, Cells(x, y)) Is Nothing Then
       If Now() >= Range("b2") And Now() <= Range("b3") Then
              On Error Resume Next
              If Target.Value = "" Then
                 Target.Selection.ClearComments
                 Range(x, y).Offset(39, 0).Value = ""
              End If
          Cells(x + 39, y) = ActiveCell.Value
          Cells(x, y).AddComment
          Cells(x, y).Comment.Visible = False
          Cells(x, y).Comment.Text Text:="1er semèstre"
               If Target.Value = "" Then
                   Target.ClearComments
               End If
       End If
       If Now() >= Range("b5") And Now() <= Range("b6") Then
             On Error Resume Next
             If Target.Value = "" Then
                Cells(x, y).Selection.ClearComments
                Range(x, y).Offset(66, 0).Value = ""
             End If
          Cells(x + 66, y) = ActiveCell.Value
          Cells(x, y).AddComment
          Cells(x, y).Comment.Visible = False
          Cells(x, y).Comment.Text Text:="2ème semèstre"
               If Target.Value = "" Then
                   Target.ClearComments
               End If
       End If
End If
Target.Select
Application.EnableEvents = True
End Sub
Rechercher des sujets similaires à "touche delete"