XL 2013 colorier cellule avec double click

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 !

CGU2022.

XLDnaute Junior
Bonsoir à toutes et à tous
Ci dessous le code que j'ai, qui colore et décolore une cellule par double click dans les cellules b3:b20.
1- comment éviter le message "feuille protégée"
2- comment utiliser range avec plusieurs plage et cellules (exemple: B3:B5 + B7 + B9:B10)
3- "Target, Range("b3:b20")" appliquer la macro dans cette plage mais seulement la cellule de la colonne A n'est pas vide.( exemple B3 si A3<>"")

En tout cas, Un grand Merci...
Grace à ce forum j' apprend et découvre beaucoup. 👍 👍 👍




VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

'code qui colore la cellule avec dble click
    If Not Application.Intersect(Target, Range("b3:b20")) Is Nothing Then
        With Target
        ActiveSheet.Unprotect Password:="123"
            If Selection.Interior.ColorIndex = 6 Then
            Selection.Interior.ColorIndex = xlNone
            Else
            Selection.Interior.ColorIndex = 6
            End If
        End With
        ActiveSheet.Protect Password:="123"
    End If
End Sub
 

Pièces jointes

Bonsoir,

Essayez :
VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   Cancel = True
   If Application.Intersect(Target, Range("B3:B5,B7,B9:B10")) Is Nothing Then Exit Sub
   With Target
      ActiveSheet.Unprotect Password:="123"
      If .Offset(, -1) <> "" Then .Interior.ColorIndex = IIf(.Interior.ColorIndex = 6, xlNone, 6)
      ActiveSheet.Protect Password:="123"
   End With
End Sub
 

Pièces jointes

Dernière édition:
Bonsoir CGU,
Un essai en PJ avec :
VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'code qui colore la cellule avec dble click
    If Not Application.Intersect(Target, Range("B3:B5,B7,B9:B10")) Is Nothing Then
        With Target
        ActiveSheet.Unprotect Password:="123"
            If Cells(Target.Row, Target.Column - 1) <> "" Then
                If Selection.Interior.ColorIndex = 6 Then
                    Selection.Interior.ColorIndex = xlNone
                Else
                    Selection.Interior.ColorIndex = 6
                End If
                Cells(Target.Row, Target.Column + 1).Select
            End If
        End With
        ActiveSheet.Protect Password:="123"
    End If
End Sub
 

Pièces jointes

Bonsoir,

Essayez :
VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   Cancel = True
   If Application.Intersect(Target, Range("B3:B5,B7,B9:B10")) Is Nothing Then Exit Sub
   With Target
      ActiveSheet.Unprotect Password:="123"
      If .Offset(, -1) <> "" Then .Interior.ColorIndex = IIf(.Interior.ColorIndex = 6, xlNone, 6)
      ActiveSheet.Protect Password:="123"
   End With
End Sub
merci, merci 😉
 
Bonsoir CGU,
Un essai en PJ avec :
VB:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'code qui colore la cellule avec dble click
    If Not Application.Intersect(Target, Range("B3:B5,B7,B9:B10")) Is Nothing Then
        With Target
        ActiveSheet.Unprotect Password:="123"
            If Cells(Target.Row, Target.Column - 1) <> "" Then
                If Selection.Interior.ColorIndex = 6 Then
                    Selection.Interior.ColorIndex = xlNone
                Else
                    Selection.Interior.ColorIndex = 6
                End If
                Cells(Target.Row, Target.Column + 1).Select
            End If
        End With
        ActiveSheet.Protect Password:="123"
    End If
End Sub
merci, merci 😉
 
- 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
234
Réponses
16
Affichages
965
Réponses
4
Affichages
495
Réponses
3
Affichages
505
Réponses
7
Affichages
545
Retour