Macro filtre ?

Vioci une macro enregistrée, le filtre s'applique jusqu'à la ligne 4000 est-ce possible de lui dire d'aller jusqu'à la dernière ligne ? merci

    Cells.Select
    ActiveWorkbook.Worksheets("Fichier").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Fichier").Sort.SortFields.Add Key:=Range( _
        "E2:E4000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    ActiveWorkbook.Worksheets("Fichier").Sort.SortFields.Add Key:=Range( _
        "A2:A4000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    With ActiveWorkbook.Worksheets("Fichier").Sort
        .SetRange Range("A1:AA4000")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With

Bonjour

Je ne peux essayer car je n'ai pas XL 2007

2 possibilités

Solution 1

Sub Test1()

  Cells.Select
  ActiveWorkbook.Worksheets("Fichier").Sort.SortFields.Clear
  ActiveWorkbook.Worksheets("Fichier").Sort.SortFields.Add Key:=Range("E2:E" & Range("E" & Rows.Count).End(xlUp).Row), _
      SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  ActiveWorkbook.Worksheets("Fichier").Sort.SortFields.Add Key:=Range("A2:A" & Range("E" & Rows.Count).End(xlUp).Row), _
      SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  With ActiveWorkbook.Worksheets("Fichier").Sort
    .SetRange Range("A1:AA" & Range("AA" & Rows.Count).End(xlUp).Row)
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
  End With
End Sub

Solution 2

Sub Test2()
Dim Nblg As Long

  ' Prendre une colonne qui aura une donnée en fin du tableau à trier
  Nblg = Range("E" & Rows.Count).End(xlUp).Row
  Cells.Select
  ActiveWorkbook.Worksheets("Fichier").Sort.SortFields.Clear
  ActiveWorkbook.Worksheets("Fichier").Sort.SortFields.Add Key:=Range("E2:E" & Nblg), _
      SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  ActiveWorkbook.Worksheets("Fichier").Sort.SortFields.Add Key:=Range("A2:A" & Nblg), _
      SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  With ActiveWorkbook.Worksheets("Fichier").Sort
    .SetRange Range("A1:AA" & Nblg)
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
  End With
End Sub

La deuxième est très bien, merci.

Rechercher des sujets similaires à "macro filtre"