Combiner 2 macros

Résolu
surplus Messages postés 673 Date d'inscription   Statut Membre Dernière intervention   -  
surplus Messages postés 673 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,
j'ai 2 macros dans la feuille
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$8" Then
If Target Is Nothing Then Exit Sub '<= 7 Then Exit Sub
If Target > 7 Then MsgBox "ID Commerçant 7 caractères": Application.Undo
End If
If Target.Address = "$H$6" Then
If Target.Value = "En Cours" Then
ActiveSheet.Tab.ColorIndex = 35
Else
If Target.Value = "Attente Action" Then
ActiveSheet.Tab.Color = RGB(255, 0, 0)
Else
If Target.Value = "Cloturé" Then
ActiveSheet.Tab.Color = RGB(39, 82, 18)

End If
End If
End If
End If
End Sub
mais elles ne fonctionne pas les 2 ensemble comment combiner les 2?

fichier exemple
https://www.cjoint.com/c/KFgriU7tcoe
merci

Slts               A bientôt 
Surplus

3 réponses

  1. Le Pingou Messages postés 12274 Date d'inscription   Statut Contributeur Dernière intervention   1 476
     
    Bonjour,
    Il n'y a pas de deuxième macro dans votre classeur!
    que voulez-vous comme résultat...?
    0
    1. surplus Messages postés 673 Date d'inscription   Statut Membre Dernière intervention   4
       
      oui disons que j'ai 2 parties
      Private Sub Worksheet_Change(ByVal Target As Range)
      If Target.Address = "$C$8" Then
      If Target Is Nothing Then Exit Sub '<= 7 Then Exit Sub
      If Target > 7 Then MsgBox "ID Commerçant 7 caractères": Application.Undo
      End If

      qui me limite la cellule C8 a 7 caracteres
      et l'autre qui me change la couleur de l'onglet suivant la valeur de H6

      If Target.Address = "$H$6" Then
      If Target.Value = "En Cours" Then
      ActiveSheet.Tab.ColorIndex = 35
      Else
      If Target.Value = "Attente Action" Then
      ActiveSheet.Tab.Color = RGB(255, 0, 0)
      Else
      If Target.Value = "Cloturé" Then
      ActiveSheet.Tab.Color = RGB(39, 82, 18)

      End If
      End If
      End If
      End If
      End Sub

      et dans l'etat actuel ça marche pas en mettent les 2 parties de la macro
      je m'apperçois aussi que j'avais mis des validations de donées dans la cellule C8 il faudrait l'enlever pour le test merci
      0
  2. Frenchie83 Messages postés 2254 Statut Membre 339
     
    Bonjour,
    Essayez ceci
    Private Sub Worksheet_Change(ByVal Target As Range)
        On Error GoTo Sortie
        Application.EnableEvents = False
        If Target.Address = "$C$8" Then
            If Not Target Is Nothing And Len(Target) > 7 Then
                MsgBox "ID Commerçant 7 caractères"
                Application.Undo
            End If
        End If
        If Target.Address = "$H$6" Then
            If Target.Value = "En Cours" Then
                ActiveSheet.Tab.ColorIndex = 35
            ElseIf Target.Value = "Attente Action" Then
                    ActiveSheet.Tab.Color = RGB(255, 0, 0)
            ElseIf Target.Value = "Cloturé" Then
                ActiveSheet.Tab.Color = RGB(39, 82, 18)
            End If
        End If
        
    Sortie:
        Application.EnableEvents = True
    End Sub

    Cdlt
    0
  3. surplus Messages postés 673 Date d'inscription   Statut Membre Dernière intervention   4
     
    Bonjour
    ca fonctionne tres bien
    grand merci
    0