Ameliorer code

XL 2007 Bonsoir a tous et toutes forum bonsoir

juste un petit renseignement, est 'il possible d'améliorer ce code surtout le code Case "$F$3", etc, etc qui est repetitif, c'est tout

Merci a vous

'*** SUR DOUBLE CLIC CHANGE LA COULEUR CELLULE F3:F13 EN GRIS 16 OU FOND VERT CLAIR 4
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Application.ScreenUpdating = False
With Target
Select Case .Address
Case "$F$3", "$F$4", "$F$5", "$F$6", "$F$7", "$F$8", "$F$9", "$F$10", "$F$11", "$F$12", "$F$13"

If .Interior.ColorIndex = xlNone Then .Interior.ColorIndex = 16: Exit Sub
If .Interior.ColorIndex = 16 Then .Interior.ColorIndex = 4: Exit Sub
If .Interior.ColorIndex = 4 Then .Interior.ColorIndex = 16: Exit Sub
Range("G3").Select
End Select
End With
Application.ScreenUpdating = True
End Sub

bonne fin d'apres midi

Raymond

Bonsoir,

essaie avec ce code :

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Range("F3:F13"), Target) Is Nothing Then
    With Target
        If .Interior.ColorIndex = xlNone Then .Interior.ColorIndex = 16: Cancel = True: Exit Sub
        .Interior.ColorIndex = IIf(.Interior.ColorIndex = 16, 4, 16)
        Range("G3").Select
    End With
End If
Cancel = True
End Sub

Bonsoir Félix, forum

C'est comme ca que je voulais faire, bien sur pourquoi je n'y ai pas penser avant, NON sérieux mais un peu d'humour, je déconne, c'est ma facon de te remercier ca marche très bien, je vais l'adopter a mon programme principal des maintenant.

Passe une bonne soirée et encore merci

Bye

Raymond

Rechercher des sujets similaires à "ameliorer code"