macro de tri sur les feuilles numériques d'un classeur

  • Initiateur de la discussion Initiateur de la discussion superbog
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

superbog

XLDnaute Occasionnel
Bonjour,

Je bloque sur une macro qui devrait être simple (honte à moi), j'ai un classeur avec des pages numériques et d'autres qui ne le sont pas.
Je souhaite que les cellules C6:H2000 soient triées par la colonne C par ordre croissant.

voici la macro que j'ai préparée

Code:
Sub trier_dil()
Dim WS As Worksheet

For Each WS In Worksheets
     
  If IsNumeric(WS.Name) Then
        
         ActiveSheet.Sort.SortFields.Clear
         ActiveSheet.Sort.SortFields.Add Key:=Range( _
        "C6:C2000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
      With ActiveSheet.Sort
        .SetRange Range("C6:H2000")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
        
      End With
    
    End If
       
    Next WS
  
MsgBox ("tri des diligences terminé")

End Sub

merci de m'aider
 
Re : macro de tri sur les feuilles numériques d'un classeur

Bonjour,

essaye en modifiant comme suit :
Code:
Sub trier_dil()
Dim WS As Worksheet
For Each WS In Worksheets
With WS
    If IsNumeric(.Name) Then
        .Sort.SortFields.Clear
        .Sort.SortFields.Add Key:=Range("C6:C2000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
        With .Sort
            .SetRange Range("C6:H2000")
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    End If
End With
Next WS

bon après midi
@+
 
Re : macro de tri sur les feuilles numériques d'un classeur

Re,

Code:
Sub trier_dil()
Dim WS As Worksheet
For Each WS In Worksheets
    With WS
        If IsNumeric(.Name) Then
            With .Sort
                .SortFields.Clear
                .SortFields.Add Key:=Range("C6:C2000"), SortOn:=xlSortOnValues, _
                    Order:=xlAscending, DataOption:=xlSortNormal
                .SetRange Range("C6:H2000")
                .Header = xlGuess
                .MatchCase = False
                .Orientation = xlTopToBottom
                .SortMethod = xlPinYin
                .Apply
            End With
        End If
    End With
Next WS
 
MsgBox ("tri des diligences terminé")

End Sub
 
Re : macro de tri sur les feuilles numériques d'un classeur

Re,

manquait un "ws"
Code:
Sub trier_dil()
Dim WS As Worksheet
For Each WS In Worksheets
    With WS
        If IsNumeric(.Name) Then
            With .Sort
                .SortFields.Clear
                .SortFields.Add Key:=ws.Range("C6:C2000"), SortOn:=xlSortOnValues, _
                    Order:=xlAscending, DataOption:=xlSortNormal
                .SetRange WS.Range("C6:H2000")
                .Header = xlGuess
                .MatchCase = False
                .Orientation = xlTopToBottom
                .SortMethod = xlPinYin
                .Apply
            End With
        End If
    End With
Next WS
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

  • Question Question
XL 2021 listbox
Réponses
18
Affichages
286
Réponses
4
Affichages
179
Réponses
17
Affichages
1 K
Réponses
6
Affichages
1 K
Réponses
11
Affichages
781
Réponses
8
Affichages
1 K
Retour