Cases à cocher pour cacher des lignes

gcas

XLDnaute Nouveau
Bonjour
Je souhaiterais cacher des lignes conformément aux critéres suivants (voir fichier ci-joint) :
1. Si case à cocher "PV" (D1) est cochée : Ne conserver que les lignes qui comportent un "x" dans la colonne "PV" (A)
2. Si case à cocher "PAC" (D2) est cochée : Ne conserver que les lignes qui comportent un "x" dans la colonne "PAC" (B)
Merci d'avance pour votre aide
 

Pièces jointes

  • lignes_a_cacher_00.xlsm
    19.2 KB · Affichages: 48

phlaurent55

Nous a quittés en 2020
Repose en paix
Re : Cases à cocher pour cacher des lignes

Bonjour gcas,

avec ces codes:
Code:
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
For Each cellule In Range("A2:A" & Range("A65535").End(xlUp).Row)
If cellule <> "x" Then Rows(cellule.Row).EntireRow.Hidden = True
Next cellule
Else
For Each cellule In Range("A2:A" & Range("A65535").End(xlUp).Row)
If cellule <> "x" Then Rows(cellule.Row).EntireRow.Hidden = False
Next cellule
End If
End Sub

Private Sub CheckBox2_Click()
If CheckBox2.Value = True Then
For Each cellule In Range("B2:B" & Range("B65535").End(xlUp).Row)
If cellule <> "x" Then Rows(cellule.Row).EntireRow.Hidden = True
Next cellule
Else
For Each cellule In Range("B2:B" & Range("B65535").End(xlUp).Row)
If cellule <> "x" Then Rows(cellule.Row).EntireRow.Hidden = False
Next cellule
End If
End Sub
à+
Philippe
 

phlaurent55

Nous a quittés en 2020
Repose en paix
Re : Cases à cocher pour cacher des lignes

Re,

ou peut-être avec ceci:
Code:
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
For i = 1 To Range("A65535").End(xlUp).Row
Rows(i).EntireRow.Hidden = False
Next i
For Each cellule In Range("A2:A" & Range("A65535").End(xlUp).Row)
If cellule <> "x" Then Rows(cellule.Row).EntireRow.Hidden = True
Next cellule
Else
For Each cellule In Range("A2:A" & Range("A65535").End(xlUp).Row)
If cellule <> "x" Then Rows(cellule.Row).EntireRow.Hidden = False
Next cellule
End If
End Sub

Private Sub CheckBox2_Click()
If CheckBox2.Value = True Then
For i = 1 To Range("B65535").End(xlUp).Row
Rows(i).EntireRow.Hidden = False
Next i
For Each cellule In Range("B2:B" & Range("B65535").End(xlUp).Row)
If cellule <> "x" Then Rows(cellule.Row).EntireRow.Hidden = True
Next cellule
Else
For Each cellule In Range("B2:B" & Range("B65535").End(xlUp).Row)
If cellule <> "x" Then Rows(cellule.Row).EntireRow.Hidden = False
Next cellule
End If
End Sub
à+
Philippe
 

DoubleZero

XLDnaute Barbatruc
Re : Cases à cocher pour cacher des lignes

Bonjour, gcas, Philippe :), le Forum,

Et comme ceci ?

Code:
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then Columns("A:B").AutoFilter Field:=1, Criteria1:="x"
If CheckBox1.Value = False Then Columns("A:B").AutoFilter
End Sub
Private Sub CheckBox2_Click()
If CheckBox2.Value = True Then Columns("A:B").AutoFilter Field:=2, Criteria1:="x"
If CheckBox2.Value = False Then Columns("A:B").AutoFilter
End Sub

A bientôt :)
 

gcas

XLDnaute Nouveau
Re : Cases à cocher pour cacher des lignes

Bonjour DoubleZero, Philippe
Merci pour vos propositions :)
Est-il possible d'adapter le code de DoubleZero pour prendre en compte une sélection multiple ?
Exemple : PV (D1) et PAC (D2) cochés -> Affichage des lignes 1 à 9 sauf la ligne 6 (voir fichier ci-joint)
Merci d'avance
 

Pièces jointes

  • lignes_a_cacher_01.xlsm
    20.5 KB · Affichages: 42

gcas

XLDnaute Nouveau
Re : Cases à cocher pour cacher des lignes

Re-bonjour Philippe, le Forum
Si uniquement cases à cocher PV et PAC, la solution avec une case à cocher supplémentaire (PV-PAC) conviendrait
J'ai reformulé mon problème dans l'Excel ci-joint
Merci d'avance et bonne fin de soirée à tous
GCAS
 

Pièces jointes

  • lignes_a_cacher_02.xlsm
    22.7 KB · Affichages: 62
  • lignes_a_cacher_02.xlsm
    22.7 KB · Affichages: 73
  • lignes_a_cacher_02.xlsm
    22.7 KB · Affichages: 51

tototiti2008

XLDnaute Barbatruc
Re : Cases à cocher pour cacher des lignes

Bonjour à toutes et tous, :)

un essai (pour le plaisir de prendre le relai ;))
 

Pièces jointes

  • lignes_a_cacher_02.xlsm
    35.5 KB · Affichages: 53
  • lignes_a_cacher_02.xlsm
    35.5 KB · Affichages: 54
  • lignes_a_cacher_02.xlsm
    35.5 KB · Affichages: 54
Dernière édition:

gcas

XLDnaute Nouveau
Re : Cases à cocher pour cacher des lignes

Bonjour tototiti2008
Un grand merci pour ton aide très précieuse
Une dernière chose cependant : Lorsque l'on ajoute un boutton à option (voir fichier ci-joint), une erreur ce produit (il semblerait qu'Excel ne fait pas la différence entre boutton à option et case à cocher...)
Auriez-vous une solution ?
Merci d'avance
 

Pièces jointes

  • lignes_a_cacher_04.xlsm
    38 KB · Affichages: 44

tototiti2008

XLDnaute Barbatruc
Re : Cases à cocher pour cacher des lignes

Bonsoir gcas,

En effet, bon à savoir

essaye comme ça

Code:
Dim OO As OLEObject, Formule As String, Champ As Long, Ligne As Long, Colonne As Long
    With Sheets("Sheet1")
        Formule = ""
        Ligne = .Range("Titr").Row + 1
        Colonne = .Range("Titr").Range("A1").Column
        For Each OO In .OLEObjects
            If OO.progID Like "Forms.CheckBox*" Then
                If OO.Object.Value Then
                    Champ = Application.Match(OO.Object.Caption, .Range("Titr"), 0)
                    If Formule <> "" Then Formule = Formule & ","
                    Formule = Formule & .Cells(Ligne, Colonne + Champ - 1).Address(False, False) & "=""x"""
                End If
            End If
        Next
        If Formule = "" Then
            AfficheTout
        Else
            Formule = "=OR(" & Formule & ")"
            .Range("Crit").Range("A2").Formula = Formule
            .Range("Liste[#All]").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=.Range("Crit"), Unique:=False
        End If
    End With
End Sub

Sub AfficheTout()
    With Sheets("Sheet1")
        If .FilterMode Then .ShowAllData
        For Each OO In .OLEObjects
            If OO.progID Like "Forms.CheckBox*" Then
                If OO.Object.Value Then OO.Object.Value = False
            End If
        Next
    End With
End Sub
 

Discussions similaires

Statistiques des forums

Discussions
312 479
Messages
2 088 744
Membres
103 944
dernier inscrit
Stbj