Erreur de syntaxe

mornebulle Messages postés 1 Statut Membre -  
f894009 Messages postés 17417 Date d'inscription   Statut Membre Dernière intervention   -
bonjour à toutes et tous,

j'ai créé la macro ci dessous :
Sub oct()
If [as27] = 1 Then
[au27].PrintPreview
[as27] = "OK"
[ao27].Copy
[ao27].PasteSpecial Paste:=xlPasteValues
[ap27].Copy
[ap27].PasteSpecial Paste:=xlPasteValues
[am27] = ""
[an27] = ""
Dim plage As Range
Set plage = ThisWorkbook.Worksheets("stock").Range("ag27:ag300")
Monchiffre = [ao27]
For Each cell In plage
If cell.Value = Monchiffre Then
cell.Value = 0
End If
Next cell
Monchiffre = [ap27]
For Each cell In plage
If cell.Value = Monchiffre Then
cell.Value = 0
End If
Next cell
End If
End Sub

Elle fonctionne très bien, mais j'ai essayé de faire une boucle de la ligne 27 à la ligne 300 (avec la commande for ), j'ai des erreurs de syntaxe.
Je vous remercie d'avance pour votre aide

1 réponse

  1. f894009 Messages postés 17417 Date d'inscription   Statut Membre Dernière intervention   1 717
     
    Bonjour,

    En dehors du fait qu'une seule boucle suffit, pas d'erreur

    Sub oct()
        Dim plage As Range
        If [AS27] = 1 Then
            [AU27].PrintPreview
            [AS27] = "OK"
            [AO27].Copy
            [AO27].PasteSpecial Paste:=xlPasteValues
            [AP27].Copy
            [AP27].PasteSpecial Paste:=xlPasteValues
            [AM27] = ""
            [AN27] = ""
            Set plage = ThisWorkbook.Worksheets("stock").Range("AG27:AG300")
            Monchiffre1 = [AO27]
            Monchiffre2 = [AP27]
    
            For Each cell In plage
                If cell.Value = Monchiffre1 Or cell.Value = Monchiffre2 Then
                    cell.Value = 0
                End If
            Next cell
        End If
    End Sub
    
    0