XL 2010 Cellule changement de couleur double clic

jokerfidelio

XLDnaute Occasionnel
Bonjour a tous,

Suite a une recherche sur le forum j'aimerais adapter ce code, qui fonctionne tres bien mais lorsque
je protège mes cellules avec un mot de passe, j'ai un message d'erreur.
Comment rendre ce code compatible avec la protection des cellules ?

VB:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Not Application.Intersect(Target, Range("G14:H90")) Is Nothing Then
With Target
If Selection.Interior.ColorIndex = 46 Then
Selection.Interior.ColorIndex = 48
Else
Selection.Interior.ColorIndex = 46
End If
End With
End If
End Sub


Merci de votre aide.
 

jokerfidelio

XLDnaute Occasionnel
Voici le code que j'ai copier :
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Unprotect Password:="TOTO"
If Not Application.Intersect(Target, Range("G14:H90")) Is Nothing Then
With Target
If Selection.Interior.ColorIndex = 46 Then
Selection.Interior.ColorIndex = 48
Else
Selection.Interior.ColorIndex = 46
Protect Password:="TOTO"
End If
End With
End If
End Sub
 

jokerfidelio

XLDnaute Occasionnel
autant pour moi c'est mieux ainsi :

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Unprotect Password:="TOTO"
If Not Application.Intersect(Target, Range("G14:H90")) Is Nothing Then
With Target
If Selection.Interior.ColorIndex = 46 Then
Selection.Interior.ColorIndex = 48
Else
Selection.Interior.ColorIndex = 46
End If
End With
End If
Protect Password:="TOTO"
End Sub
 

Discussions similaires

Statistiques des forums

Discussions
312 305
Messages
2 087 070
Membres
103 453
dernier inscrit
Choupi