Microsoft 365 tri trop long

Usine à gaz

XLDnaute Barbatruc
Supporter XLD
Bonjour à toutes et à tous :)

J'ai fait un code pour faire mes tris, mais il est très long.
VB:
Sub tri_RdVs_alpha()
Application.EnableEvents = False
ActiveSheet.Unprotect Password:=""
Range([a6], Cells(Rows.Count, "a").End(xlUp)).RowHeight = 55
    With ActiveSheet 'Feuil3 'CodeName
    If .FilterMode Then .ShowAllData 'si la feuille est filtrée
    With .Rows("6:" & .Range("a65536").End(xlUp).Row)
        If .Row < 6 Then Exit Sub 'sécurité
        .Sort .Columns(1), xlAscending, Header:=xlNo
    End With
   
    For i = 6 To Range("J" & Rows.Count).End(xlUp).Row
    If Cells(i, 10) = "NPR" Or Cells(i, 10) = "RdV Fait" Then Rows(i).Hidden = True
    'If Cells(i, 10) = "NPR" Or Cells(i, 10) = "RdV Fait" Then Rows(i).RowHeight = 55
    Next i

End With
[a3].Select
ActiveSheet.Protect Password:="", DrawingObjects:=True, Contents:=True, Scenarios:=True
Application.EnableEvents = True
End Sub
Voilà le responsable (enfin, je pense) :
For i = 6 To Range("J" & Rows.Count).End(xlUp).Row
If Cells(i, 10) = "NPR" Or Cells(i, 10) = "RdV Fait" Then Rows(i).Hidden = True
'If Cells(i, 10) = "NPR" Or Cells(i, 10) = "RdV Fait" Then Rows(i).RowHeight = 55
Next i
J'ai tenté les 2 codes ".Hidden = True" et ".RowHeight = 55" = même temps d'exécution (+ de 15 secondes)
Mon fichier que je ne peux pas joindre contient environ 60.000 lignes.

Je ne vois pas comment faire :mad:
Auriez-vous la solution pour accélérer le code ?

Je continue à chercher ...
Je vous remercie,
Amicalement,
lionel,
 

Phil69970

XLDnaute Barbatruc
Re

Une piste tu traites l'info (ton code) en 2 parties pour voir laquelle est la plus lente

Tu désactives tu lances la macro sans cette partie

'For i = 6 To Range("J" & Rows.Count).End(xlUp).Row
'If Cells(i, 10) = "NPR" Or Cells(i, 10) = "RdV Fait" Then Rows(i).Hidden = True
'If Cells(i, 10) = "NPR" Or Cells(i, 10) = "RdV Fait" Then Rows(i).RowHeight = 55
'Next i

Puis après tu lances juste le reste exemple

VB:
Sub tri_RdVs_alpha()
Application.EnableEvents = False
ActiveSheet.Unprotect Password:=""
Range([a6], Cells(Rows.Count, "a").End(xlUp)).RowHeight = 55
    With ActiveSheet 'Feuil3 'CodeName
    If .FilterMode Then .ShowAllData 'si la feuille est filtrée
        With .Rows("6:" & .Range("a65536").End(xlUp).Row)
            If .Row < 6 Then Exit Sub 'sécurité
            .Sort .Columns(1), xlAscending, Header:=xlNo
        End With
 
   'Ici tu mets un point d'arret tu regardes le temps d'execution
   LaSuite
 
'    For i = 6 To Range("J" & Rows.Count).End(xlUp).Row
'        If Cells(i, 10) = "NPR" Or Cells(i, 10) = "RdV Fait" Then Rows(i).Hidden = True
'        'If Cells(i, 10) = "NPR" Or Cells(i, 10) = "RdV Fait" Then Rows(i).RowHeight = 55
'    Next i

End With
[a3].Select
ActiveSheet.Protect Password:="", DrawingObjects:=True, Contents:=True, Scenarios:=True
Application.EnableEvents = True
End Sub

Sub LaSuite()
'ici le reste de ta macro
    For i = 6 To Range("J" & Rows.Count).End(xlUp).Row
        If Cells(i, 10) = "NPR" Or Cells(i, 10) = "RdV Fait" Then Rows(i).Hidden = True
        'If Cells(i, 10) = "NPR" Or Cells(i, 10) = "RdV Fait" Then Rows(i).RowHeight = 55
    Next i
End Sub

Quand tu auras trouvé quelle partie est la plus lente on verra.....

@Phil69970
 

Usine à gaz

XLDnaute Barbatruc
Supporter XLD
Re

Une piste tu traites l'info (ton code) en 2 parties pour voir laquelle est la plus lente

Tu désactives tu lances la macro sans cette partie



Puis après tu lances juste le reste exemple

VB:
Sub tri_RdVs_alpha()
Application.EnableEvents = False
ActiveSheet.Unprotect Password:=""
Range([a6], Cells(Rows.Count, "a").End(xlUp)).RowHeight = 55
    With ActiveSheet 'Feuil3 'CodeName
    If .FilterMode Then .ShowAllData 'si la feuille est filtrée
        With .Rows("6:" & .Range("a65536").End(xlUp).Row)
            If .Row < 6 Then Exit Sub 'sécurité
            .Sort .Columns(1), xlAscending, Header:=xlNo
        End With
 
   'Ici tu mets un point d'arret tu regardes le temps d'execution
   LaSuite
 
'    For i = 6 To Range("J" & Rows.Count).End(xlUp).Row
'        If Cells(i, 10) = "NPR" Or Cells(i, 10) = "RdV Fait" Then Rows(i).Hidden = True
'        'If Cells(i, 10) = "NPR" Or Cells(i, 10) = "RdV Fait" Then Rows(i).RowHeight = 55
'    Next i

End With
[a3].Select
ActiveSheet.Protect Password:="", DrawingObjects:=True, Contents:=True, Scenarios:=True
Application.EnableEvents = True
End Sub

Sub LaSuite()
'ici le reste de ta macro
    For i = 6 To Range("J" & Rows.Count).End(xlUp).Row
        If Cells(i, 10) = "NPR" Or Cells(i, 10) = "RdV Fait" Then Rows(i).Hidden = True
        'If Cells(i, 10) = "NPR" Or Cells(i, 10) = "RdV Fait" Then Rows(i).RowHeight = 55
    Next i
End Sub

Quand tu auras trouvé quelle partie est la plus lente on verra.....

@Phil69970
Re-Bonjour,

je l'avais déjà fait, c'est pour cela que j'ai vu que la boucle en est responsable.
Mais avec le Application.ScreenUpdating = False, ça va bcp mieux :)
 

Statistiques des forums

Discussions
311 709
Messages
2 081 779
Membres
101 816
dernier inscrit
Jfrcs