Aide pour une correction de code

Bonjour

j'ai ajouter un code avec un code déjà existant le soucis et que il affiche un message d'erreur qui ce traduit par un problème de doublon avec

worksheet_change(ByVal target As Range)

le truc c'est que je souhaite ajouter le code suivant :

Private Sub worksheet_change(ByVal target As Range)

If Not Intersect(target, Range("C4:C4,C10:O11")) Is Nothing Then
col = target.Column

    If Cells(4, col) = "4F 4G" Then
        Cells(15, col) = Cells(12, col) * Cells(15, 2)
        Cells(33, col) = Cells(12, col) * Cells(33, 2)
        Cells(51, col) = Cells(12, col) * Cells(51, 2)
        Cells(58, col) = Cells(12, col) * Cells(58, 2)
     Else: Exit Sub
        End If
    End If
End Sub

a celui ci :

Private Sub worksheet_change(ByVal target As Range)
    If Not Intersect(target, Range("C4:Q4,C10:Q10")) Is Nothing Then
        Set ws = Sheets("Grammage")
        trouve = False
        For col = 1 To ws.Cells(1, Columns.Count).End(xlToLeft).Column
            If UCase(ws.Cells(1, col)) = UCase(Cells(4, target.Column)) Then
                trouve = True
                Exit For
            End If
        Next col
        If Not trouve Then
            MsgBox "La formule " & Cells(4, target.Column) & " non trouvée dans la feuille grammages"
            Exit Sub
        End If
        trouve = False
        For i = 15 To Cells(Rows.Count, 1).End(xlUp).Row
        If UCase(Left(Cells(i, 1), 5)) = "TOTAL" Then Exit Sub
            If Cells(i, target.Column) <> "" And Cells(i, 1) <> "" Then
                For ligne = 1 To ws.Cells(Rows.Count, 1).End(xlUp).Row
                    If UCase(ws.Cells(ligne, 1)) = UCase(Cells(i, 1)) Then
                        trouve = True
                        Exit For
                    End If
                Next ligne
                If Not trouve Then
                    MsgBox "La garniture " & Cells(target.Row, 1) & " non trouvée dans la feuille grammages"
                    Exit Sub
                End If
                Cells(i, target.Column) = Cells(12, target.Column) * ws.Cells(ligne, col)
            End If
        Next i
        End If
    End If
End Sub

j'ai essayer plusieurs manipulations mais sans succès en trotte ça :

Private Sub worksheet_change(ByVal target As Range)
    If Not Intersect(target, Range("C4:Q4,C10:Q10")) Is Nothing Then
        Set ws = Sheets("Grammage")
        trouve = False
        For col = 1 To ws.Cells(1, Columns.Count).End(xlToLeft).Column
            If UCase(ws.Cells(1, col)) = UCase(Cells(4, target.Column)) Then
                trouve = True
                Exit For
            End If
        Next col
        If Not trouve Then
            MsgBox "La formule " & Cells(4, target.Column) & " non trouvée dans la feuille grammages"
            Exit Sub
        End If
        trouve = False
        For i = 15 To Cells(Rows.Count, 1).End(xlUp).Row
        If UCase(Left(Cells(i, 1), 5)) = "TOTAL" Then Exit Sub
            If Cells(i, target.Column) <> "" And Cells(i, 1) <> "" Then
                For ligne = 1 To ws.Cells(Rows.Count, 1).End(xlUp).Row
                    If UCase(ws.Cells(ligne, 1)) = UCase(Cells(i, 1)) Then
                        trouve = True
                        Exit For
                    End If
                Next ligne
                If Not trouve Then
                    MsgBox "La garniture " & Cells(target.Row, 1) & " non trouvée dans la feuille grammages"
                    Exit Sub
                End If
                Cells(i, target.Column) = Cells(12, target.Column) * ws.Cells(ligne, col)
            End If
        Next i
        If Not Intersect(target, Range("C4:C4,C10:O11")) Is Nothing Then
col = target.Column

    If Cells(4, col) = "4F 4G" Then
        Cells(15, col) = Cells(12, col) * Cells(15, 2)
        Cells(33, col) = Cells(12, col) * Cells(33, 2)
        Cells(51, col) = Cells(12, col) * Cells(51, 2)
        Cells(58, col) = Cells(12, col) * Cells(58, 2)
     Else: Exit Sub
        End If
    End If
End Sub

mais il me marque une erreur de compilation: Bloc If sans End If

j'avoue que je suis perdu !

pouvez vous m'explique mon erreur ?

Cordialement

Hello,

il te manque 1 end if

If Not Intersect(target, Range("C4:Q4,C10:Q10")) Is Nothing Then

end if à placer avant le end sub

Bonjour Magouel,

En plus de la réponse qu'à donné Rag02700 que je salue

Pense à utiliser le menu "Compiler VBAProject"

image

Ce qui vous aurait donné

2022 05 21 16h49 11

A+

Rechercher des sujets similaires à "aide correction code"