Optimisation de code pour éxécution plus rapide

treza88

XLDnaute Occasionnel
Bonjour a tous,

Je vous sollicite pour voir si il y a une solution pour rendre plus rapide l’exécution d'une commande de masquage de ligne en fonction d'une cellule contenant un Zéro ou pas.
Le code ci dessous fonctionne, mais comme la feuille comporte un peu moins de 400 lignes le code si dessous est un peu lent a s’exécuter.
Existe t il un autre code plus rapide?


Code:
Sub masque_0()
  Application.Calculation = xlCalculationManual
  Dim i As Integer
   
  If ActiveSheet.Index = 1 Then

  For i = 8 To Range("E65536").End(xlUp).Row
  If Cells(i, 7).Value = 0 Then
  Cells(i, 7).EntireRow.Hidden = True
  End If
  Next i
   
  ElseIf ActiveSheet.Index = 6 Then
  For i = 3 To Range("D65536").End(xlUp).Row
  If Cells(i, 5).Value = 0 Then
  Cells(i, 5).EntireRow.Hidden = True
  End If
  Next i
   
  ElseIf ActiveSheet.Index = 6 Then
  For i = 3 To Range("D65536").End(xlUp).Row
  If Cells(i, 4).Value = 0 Then
  Cells(i, 4).EntireRow.Hidden = True
  End If
  Next i
   
  Else
  For i = 5 To Range("D65536").End(xlUp).Row
  If Cells(i, 6).Value = 0 Then
  Cells(i, 6).EntireRow.Hidden = True
  End If
  Next i
   
  End If

Merci d'avance.
 

vgendron

XLDnaute Barbatruc
Hello
un essai avec ce code

VB:
Sub masque_0()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Dim i As Integer

Select Case ActiveSheet.Index
    Case 1
        For i = 8 To Range("E65536").End(xlUp).Row
            Cells(i, 7).EntireRow.Hidden = (Cells(i, 7).Value = 0)
       Next i
 
    Case 6
        For i = 3 To Range("D65536").End(xlUp).Row
            Cells(i, 5).EntireRow.Hidden = ((Cells(i, 5).Value = 0) Or (Cells(i, 4).Value = 0))
        Next i
 
    Case Else
        For i = 5 To Range("D65536").End(xlUp).Row
            Cells(i, 6).EntireRow.Hidden = (Cells(i, 6).Value = 0)
        Next i
End Select

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = true
End Sub
 

Discussions similaires

Réponses
6
Affichages
202
Réponses
17
Affichages
760

Statistiques des forums

Discussions
311 725
Messages
2 081 943
Membres
101 849
dernier inscrit
florentMIG