Réunir deux codes

thomasdu40

XLDnaute Occasionnel
Bonjour,

J'ai les deux codes suivants qui ne peuvent fonctionner car ce sont les mêmes événementielles. Peut-on les réunir ?

Merci.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("C6:C511")) Is Nothing Then: Exit Sub
        ThisWorkbook.Worksheets("ConstatsBRC").Visible = xlSheetHidden
        ThisWorkbook.Worksheets("ConstatsIFS").Visible = xlSheetHidden
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
  If Not Intersect([D6:D501], Target) Is Nothing Then
    On Error Resume Next
    Target.Font.ColorIndex = [couleurs].Find(Target, LookAt:=xlWhole).Font.ColorIndex
  End If
End Sub
 

Pierrot93

XLDnaute Barbatruc
Re : Réunir deux codes

Bonjour,

peut être ainsi :
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Not Intersect([D6:D501], Target) Is Nothing Then
    On Error Resume Next
    Target.Font.ColorIndex = [couleurs].Find(Target, LookAt:=xlWhole).Font.ColorIndex
  End If
  On Error GoTo 0
    If Intersect(Target, Range("C6:C511")) Is Nothing Then: Exit Sub
        ThisWorkbook.Worksheets("ConstatsBRC").Visible = xlSheetHidden
        ThisWorkbook.Worksheets("ConstatsIFS").Visible = xlSheetHidden
End Sub

bon après midi
@+
 
Dernière édition:

tototiti2008

XLDnaute Barbatruc
Re : Réunir deux codes

Bonjour thomasdu40,

un truc comme ça ?

Private Sub Worksheet_Change(ByVal Target As Range)
If not Intersect(Target, Range("C6:C511")) Is Nothing Then
ThisWorkbook.Worksheets("ConstatsBRC").Visible = xlSheetHidden
ThisWorkbook.Worksheets("ConstatsIFS").Visible = xlSheetHidden
end if
If Not Intersect([D6:D501], Target) Is Nothing Then
On Error Resume Next
Target.Font.ColorIndex = [couleurs].Find(Target, LookAt:=xlWhole).Font.ColorIndex
End If
On error goto 0
End Sub

Edit : Arf, Pierrot, content de voir que l'on est toujours sur des longueurs d'ondes compatibles ;)
 

Discussions similaires

Statistiques des forums

Discussions
312 571
Messages
2 089 809
Membres
104 278
dernier inscrit
LENZY