Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

Agregation de 2 codes ; Problème!

  • Initiateur de la discussion Initiateur de la discussion anthoYS
  • Date de début Date de début

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 ;

Voilà le code principal :

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
With Target
    If .Column = 2 Then
        Cancel = True
        If .Comment Is Nothing Then
            .AddComment
            .Comment.Shape.Width = 121.5
            .Comment.Shape.Height = 29.75
        End If
        SendKeys "%im"
    End If
    If Target.Column = 4 Then
Cells(Target.Row, 4) = Date
End If
End With
End Sub

Je veux ajouter ceci :

Code:
[COLOR="DarkOrchid"]Dim c As Long, i As Long
If Intersect(Target, Union([klj], [infinite])) Is Nothing Then Exit Sub
    c = Target.Interior.ColorIndex
    For i = 1 To Range("couple").Count
        If Range("couple").Cells(i, 1).Interior.ColorIndex = c Then
            Target.Interior.ColorIndex = Range("couple").Cells(i + 1, 1).Interior.ColorIndex
            Target.Font.ColorIndex = Range("couple").Cells(i + 1, 1).Font.ColorIndex
            i = Range("couple").Count
            Cancel = True
             End If
    Next i[/COLOR]

Mais ou le placer pour que ça fonctionne?

Merci
 
Re : Agregation de 2 codes ; Problème!

Re,

J'ai mis ensemble les codes ainsi :

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
[COLOR="DarkOrchid"]Dim c As Long, i As Long[/COLOR]
Cancel = True
With Target
    If .Column = 2 Then
        Cancel = True
        If .Comment Is Nothing Then
            .AddComment
            .Comment.Shape.Width = 121.5
            .Comment.Shape.Height = 29.75
        End If
        SendKeys "%im"
    End If
    If Target.Column = 4 Then
Cells(Target.Row, 4) = Date
End If
End With
[COLOR="#9932cc"]If Intersect(Target, Union([klj], [infinite])) Is Nothing Then Exit Sub
    c = Target.Interior.ColorIndex
    For i = 1 To Range("couple").Count
        If Range("couple").Cells(i, 1).Interior.ColorIndex = c Then
            Target.Interior.ColorIndex = Range("couple").Cells(i + 1, 1).Interior.ColorIndex
            Target.Font.ColorIndex = Range("couple").Cells(i + 1, 1).Font.ColorIndex
            i = Range("couple").Count
            Cancel = True
             End If
    Next i[/COLOR]
End Sub

La sub() sur le commentaire à ajouter par double clic fonctionne, mais pas la coloration en dégradé de la sorte.

Car voici ce que ça fait lors des doubles clics sur une cellule de la plage "infinite", rien du tout, alors que la plage "couple" est celle-ci :



Merci par avance à ceux qui auront une idée.
 

Pièces jointes

Dernière édition:
- 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

  • Question Question
Microsoft 365 worksheet_change
Réponses
29
Affichages
584
Réponses
8
Affichages
494
Réponses
2
Affichages
180
Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…