Problème erreur 91

Résolu
Lucas922 -  
 Lucas922 -
Bonjour,

Bonjour,

J'ai une erreur au niveau de macro, l'erreur 91 apparaît lors de mon filtre. Pouvez vous m''aider cordialement. Je ne maîtrise pas VBA
La macro plante au niveau de l'instruction en gras
Merci beaucoup

''Tri des alertes
ActiveWorkbook.Sheets("Alertes").Activate
ActiveWorkbook.Worksheets("Alertes").Rows(ccc & ":" & ccc).Delete

ActiveWorkbook.Worksheets("Alertes").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Alertes").AutoFilter.Sort.SortFields.Add(Range( _
"E4:E5"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = _
RGB(255, 192, 0)
With ActiveWorkbook.Worksheets("Alertes").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
ActiveWorkbook.Worksheets("Alertes").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Alertes").AutoFilter.Sort.SortFields.Add(Range( _
"E4:E5"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = _
RGB(255, 0, 0)
With ActiveWorkbook.Worksheets("Alertes").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

End Sub

3 réponses

  1. Patrice33740 Messages postés 8400 Date d'inscription   Statut Membre Dernière intervention   1 783
     
    Bonjour,

    L'erreur 91, c'est parce que le filtre n'existe pas !

    'Tri des alertes
    With ActiveWorkbook.Worksheets("Alertes")
      .Activate
      .Rows(ccc & ":" & ccc).Delete
      If .AutoFilter Is Nothing Then
        .Range("A1").AutoFilter  'Ou autre si c'est pas la ligne 1
      Else
        .ShowAllData
        .AutoFilter.Sort.SortFields.Clear
      End If
      ' etc ...
    End With

    Cordialement
    Patrice
    0
    1. Lucas922
       
      J'ai une erreur au niveau de macro, l'erreur 91 apparaît lors de mon filtre. Pouvez vous m''aider cordialement. Je ne maîtrise pas VBA
      La macro plante au niveau de l'instruction en gras
      Merci beaucoup
      ''Tri des alertes
      ActiveWorkbook.Sheets("Alertes").Activate
      ActiveWorkbook.Worksheets("Alertes").Rows(ccc & ":" & ccc).Delete
      ActiveWorkbook.Worksheets("Alertes").AutoFilter.Sort.SortFields.Clear
      ActiveWorkbook.Worksheets("Alertes").AutoFilter.Sort.SortFields.Add(Range( _
      "E4:E5"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = _
      RGB(255, 192, 0)
      With ActiveWorkbook.Worksheets("Alertes").AutoFilter.Sort
      .Header = xlYes
      .MatchCase = False
      .Orientation = xlTopToBottom
      .SortMethod = xlPinYin
      .Apply
      End With
      ActiveWorkbook.Worksheets("Alertes").AutoFilter.Sort.SortFields.Clear
      ActiveWorkbook.Worksheets("Alertes").AutoFilter.Sort.SortFields.Add(Range( _
      "E4:E5"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = _
      RGB(255, 0, 0)
      With ActiveWorkbook.Worksheets("Alertes").AutoFilter.Sort
      .Header = xlYes
      .MatchCase = False
      .Orientation = xlTopToBottom
      .SortMethod = xlPinYin
      .Apply
      End With
      End Sub

      Que dois-je corriger exactement ?
      Cordialement
      0
  2. Lucas922
     
    Bonjour, merci pour votre aide mais meme après modifs la macro m'affiche toujours cette erreur
    0
    1. Patrice33740 Messages postés 8400 Date d'inscription   Statut Membre Dernière intervention   1 783
       
      Bonjour,

      Essaies de remplacer ton code ci dessus par celui-ci (à adapter : si besoin remplacer A1 par la première cellule du tableau de données, i.e.en haut à droite) :
      'Tri des alertes
      With ActiveWorkbook.Worksheets("Alertes")
        .Activate
        .Rows(ccc & ":" & ccc).Delete
        If .AutoFilter Is Nothing Then
          .Range("A1").AutoFilter  'Ou autre si le tableau n'est pas en A1
        Else
          .ShowAllData
          .AutoFilter.Sort.SortFields.Clear
        End If
        With .AutoFilter.Sort
          .SortFields.Add(Range("E4:E5"), xlSortOnCellColor, xlAscending, , _
                          xlSortNormal).SortOnValue.Color = RGB(255, 192, 0)
          .Header = xlYes
          .MatchCase = False
          .Orientation = xlTopToBottom
          .SortMethod = xlPinYin
          .Apply
        End With
      End With
      0
  3. Lucas922
     
    Merci beaucoup pour votre aide, votre code fonctionne !!
    C'était bel et bien un problème de sélection du filtre
    0