Macro Excel pour masquer

oeufjambonfromage -  
gbinforme Messages postés 15481 Date d'inscription   Statut Contributeur Dernière intervention   -
Bonjour,

Je cherche dans un fichier à masquer à l'aide d'une macro certaines lignes. J'ai une colonne L comportant les lettres P, D, C ou A. Je souhaite masquer les lignes en état "A".

J'ai donc crée une macro (cf code ci-dessous) mais elle ne fonctionne pas. Elle bug à cette ligne " If cel.Value = "A" Then". Qqun voit l'erreur?
Merci par avance pour votre aide.

-----------------------
Sub hide()

Application.ScreenUpdating = False

Rows("1:200").Select

Dim k As Integer

k = 1

cel = Range("L" & k)

For Each cel In Selection
If cel.Value = "A" Then
cel.EntireRow.Hidden = True
k = k + 1
End If
Next cel

Range("A1").Select

End Sub
-------------------------------------------
A voir également:

1 réponse

gbinforme Messages postés 15481 Date d'inscription   Statut Contributeur Dernière intervention   4 731
 
bonjour

Tu peux essayer comme ceci :
Sub hide()

Dim cel As Range
Application.ScreenUpdating = False
For Each cel In Range("L1").Resize(200, 1)
    If cel.Value = "A" Then cel.EntireRow.Hidden = True
Next cel
Application.ScreenUpdating = True
End Sub

Sur la plage L1:L200 si une cellule est égale à "A", la ligne est cachée.
0