[VBA] - Ne pas activer Worksheet_Change lors de l'exécution de macro

Bonjour,

Durant l'exécution de mon code il y a cette partie là qui s'exécute :

Private Sub Worksheet_Change(ByVal Target As Range)
Dim lastRow&, rng As Range
On Error Resume Next
    If Target.Count = 1 Then
        lastRow = Me.Cells(Rows.Count, 3).End(xlUp).Row
        If lastRow > 2 Then
            Set rng = Me.Cells(2, 1).Resize(lastRow - 1, 11)
            If Not Intersect(Target, rng) Is Nothing Then
                If Target.Column > 5 Then
                    Application.EnableEvents = False
                    Select Case Target.Column
                    Case 6:
                        Select Case Target.Value
                                Case 1: Target.Value = "Avérée"
                                Case 2: Target.Value = "Fortement potentielle"
                                Case Else: Target.Value = "-"
                        End Select
                    Case 7:
                        Select Case Target.Value
                                Case 1: Target.Value = "Avérée"
                                Case 2: Target.Value = "Fortement potentielle"
                                Case Else: Target.Value = "-"
                        End Select
                    Case 8:
                        Select Case Target.Value
                                Case 1: Target.Value = "Très fort"
                                        With Target
                                            .Interior.Color = RGB(192, 0, 0)
                                            .Font.Color = RGB(255, 255, 255)
                                        End With
                                Case 2: Target.Value = "Fort"
                                        With Target
                                            .Interior.Color = RGB(255, 0, 0)
                                            .Font.Color = RGB(0, 0, 0)
                                        End With
                                Case 3: Target.Value = "Modéré"
                                        With Target
                                            .Interior.Color = RGB(255, 192, 0)
                                            .Font.Color = RGB(0, 0, 0)
                                        End With
                                Case 4: Target.Value = "Faible"
                                        With Target
                                            .Interior.Color = RGB(255, 255, 153)
                                            .Font.Color = RGB(0, 0, 0)
                                        End With
                                Case 5: Target.Value = "Très faible"
                                         With Target
                                            .Interior.Color = xlNone
                                            .Font.Color = RGB(0, 0, 0)
                                        End With
                                Case 6: Target.Value = "Nul"
                                        With Target
                                            .Interior.Color = xlNone
                                            .Font.Color = RGB(0, 0, 0)
                                        End With
                                Case Else: Target.Value = "-"
                                        With Target
                                            .Interior.Color = xlNone
                                            .Font.Color = RGB(0, 0, 0)
                                        End With
                        End Select
                    Case 9:
                        Select Case Target.Value
                                Case 1: Target.Value = "Très forte"
                                        With Target
                                        .Interior.Color = RGB(192, 0, 0)
                                        .Font.Color = RGB(255, 255, 255)
                                        End With
                                Case 2: Target.Value = "Forte"
                                        With Target
                                        .Interior.Color = RGB(255, 0, 0)
                                        .Font.Color = RGB(0, 0, 0)
                                        End With
                                Case 3: Target.Value = "Modérée"
                                        With Target
                                        .Interior.Color = RGB(255, 192, 0)
                                        .Font.Color = RGB(0, 0, 0)
                                        End With
                                Case 4: Target.Value = "Faible"
                                        With Target
                                        .Interior.Color = RGB(255, 255, 153)
                                        .Font.Color = RGB(0, 0, 0)
                                        End With
                                Case 5: Target.Value = "Très faible"
                                         With Target
                                        .Interior.Color = xlNone
                                        .Font.Color = RGB(0, 0, 0)
                                        End With
                                Case 6: Target.Value = "Nulle"
                                        With Target
                                        .Interior.Color = xlNone
                                        .Font.Color = RGB(0, 0, 0)
                                        End With
                                Case Else: Target.Value = "-"
                                        With Target
                                        .Interior.Color = xlNone
                                        .Font.Color = RGB(0, 0, 0)
                                        End With
                        End Select
                    End Select
                End If
            End If
        End If
    End If
Application.EnableEvents = True
End Sub

A chaque fois que le code passe d'une feuille à l'autre.

Savez-vous comment empêcher ça ?

Savez-vous également comment je peux utiliser "Case Else:" uniquement sur des nombres ? (Si j'utilise l'alphabet, alors le case else ne s'exécute pas) ? Pour cette partie, je pense que la solution viendra en déclarant chaque nombre et pas de "case else".

Merci de votre attention !

Bonne journée.

Hello,

Savez-vous également comment je peux utiliser "Case Else:" uniquement sur des nombres ? (Si j'utilise l'alphabet, alors le case else ne s'exécute pas) ? Pour cette partie, je pense que la solution viendra en déclarant chaque nombre et pas de "case else".

J'ai pas tout compris peut-être avec un fichier ?

Savez-vous comment empêcher ça ?

 Application.EnableEvents = False

Pour désactiver les événements de feuilles/classeurs...

A remettre à true la fin du code

Application.EnableEvents = True

R@g

Salut,

Merci de l'info, j'ai cherché dans mon code et, vue que je l'exécutais pas à pas, je n'activais pas Application.EnableEvents = False.

Je vois comment faire pour que tout s'exécute normalement.

Désolé du dérangement et merci du coup de main !

Rechercher des sujets similaires à "vba pas activer worksheet change lors execution macro"