Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

Microsoft 365 Masquer lignes vides

Claudy

XLDnaute Accro
Bonsoir
pour masquer des lignes vides , j'ai sorti la macro suivante:

Sub Masquer_lignes()


For Each cel In Range("A1:A30")
If cel.Value = "" Then
cel.EntireRow.Hidden = True
End If
Next
End Sub

Mais cela me semble assez long, sachant que je devrai travailler sur +/- 150 lignes.

merci d'avance pour vos lumières,
Claudy
 

sylvanu

XLDnaute Barbatruc
Supporter XLD
Bonsoir Claudy,
En rajoutant quelques lignes, on va 100 fois plus vite :
VB:
Sub Masquer_lignes()
Application.ScreenUpdating = False
Application.Calculation = xlManual
T0 = Timer
    For Each cel In Range("A2:A300")
        If cel.Value = "" Then
            cel.EntireRow.Hidden = True
        End If
    Next
MsgBox Timer - T0
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Sur mon PC sans les blocages, cela met 3.95s avec cela tombe à 0.03125s;
Essayez, mettez mes 2 premières lignes en commentaires, puis rééssayez en remettant dans l'état.
 

sylvanu

XLDnaute Barbatruc
Supporter XLD
Sorry, i don't understand.
Je remettais les lignes dans leur état de départ, c'est pour ça qu'à la fin vous ne voyez pas de différences. . C'est ça qui vous posait problème ?
Le même sans remettre en état à la fin.
Mais obtenez vous un gain en vitesse ?
 

Pièces jointes

  • EventsOFF2.xlsm
    19.4 KB · Affichages: 8

Staple1600

XLDnaute Barbatruc
Bonsoir le fil, Claudy, sylvanu

Deux variantes
VB:
Sub Masquer_lignes_B()
Application.ScreenUpdating = False
Application.Calculation = xlManual
T0 = Timer
    For Each cel In Range("A2:A300")
      cel.EntireRow.Hidden = IsEmpty(cel)
    Next
MsgBox Timer - T0
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Sub MasquerDemasquer_lignes_C()
Application.ScreenUpdating = False
Application.Calculation = xlManual
T0 = Timer
On Error Resume Next
Range("A2:A300").SpecialCells(4).Rows.Hidden = Not Range("A2:A300").SpecialCells(4).Rows.Hidden
MsgBox Timer - T0
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
La dernière offre un petit bonus
Le 1ère exécution masque les lignes, la seconde exécution les démasque
Une macro deux en un , quoi
 

Staple1600

XLDnaute Barbatruc
Re

Peut-être mais c'était juste pour le plaisir de la variante (et pour supprimer un If/End If)
Et quid de :
VB:
Sub Masquer_Ligne_D()
Application.ScreenUpdating = False
Application.Calculation = xlManual
T0 = Timer
    For Each cel In Range("A2:A300")
      cel.Rows.Hidden = cel = ""
    Next
MsgBox Timer - T0
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Sub Masquer_Ligne_E()
Application.ScreenUpdating = False
Application.Calculation = xlManual
T0 = Timer
    For Each cel In Range("A2:A300")
    If Not Len(cel) Then cel.Rows.Hidden = True
    Next
MsgBox Timer - T0
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
 

Discussions similaires

Réponses
2
Affichages
152
Réponses
14
Affichages
349
Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…