Menu déroulant filtrant

Hélène B.

XLDnaute Nouveau
Bonjour,

J'ai créé un fichier avec un certain nombre de lignes.

Afin de faciliter la consultation de ce fichier, j'aimerais pouvoir créer un menu filtrant, selon la catégorie / sous-catégorie que je souhaite filtrer.

Je joins le fichier en question (sans les chiffres, ce sera plus simple).

Je ne sais malheureusement pas faire de macros, c'est pourquoi, si une solution "manuelle" existe, j'aimerais beaucoup pouvoir l'apprendre pour la reproduire ultérieurement.

Mille mercis pour votre aide,
Hélène
 

Pièces jointes

  • Menu déroulant.xlsx
    17.4 KB · Affichages: 29

BOISGONTIER

XLDnaute Barbatruc
Repose en paix
Bonjour,


Je penses que les indentations de votre fichier ne sont pas bonnes.

Cf exemple en PJ

Code:
Dim zSaisie, NbNiv
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Set zSaisie = Range("B2:G10")
    NbNiv = 4
    If Not Intersect(zSaisie, Target) Is Nothing And Target.Count = 1 Then
      NbLig = [Tableau1].Rows.Count
      Dim TblBD(): ReDim TblBD(1 To NbLig, 1 To 2)
      Dim TblBD2(): ReDim TblBD2(1 To NbLig, 1 To 10)
      For i = 1 To NbLig
        TblBD(i, 1) = [Tableau1].Item(i, 1)
        TblBD(i, 2) = [Tableau1].Item(i, 1).IndentLevel + 1
      Next i
      Dim col(1 To 10)
      nivprec = 10
      For i = 1 To NbLig
        niv = TblBD(i, 2)
        If niv < nivprec Then col(niv) = TblBD(i, 1)
        TblBD2(i, niv) = TblBD(i, 1)
        For k = 1 To niv
          TblBD2(i, k) = col(k)
        Next k
      Next i
      Set d1 = CreateObject("Scripting.Dictionary")
      nivCourant = Target.Column - zSaisie.Column + 1
      Dim Tmp(): ReDim Tmp(1 To nivCourant)
      For k = 1 To nivCourant - 1
        Tmp(k) = Target.Offset(, -(nivCourant - k))
      Next k
      For i = 1 To UBound(TblBD2)
         témoin = True
         For k = 1 To nivCourant - 1
            If TblBD2(i, k) <> Tmp(k) Then témoin = False
         Next k
         If témoin Then d1(TblBD2(i, nivCourant)) = ""
       Next i
       If d1.Count > 0 Then
           temp = Join(d1.keys, ",")
           Target.Validation.Delete
           If temp <> "" Then Target.Validation.Add xlValidateList, Formula1:=temp
        End If
    End If
End Sub

Exemple en PJ

http://boisgontierjacques.free.fr/fichiers/DonneesValidation/MenuDeroulantIndent.xls

Boisgontier
 

Pièces jointes

  • MenuDeroulantIndent.xls
    46 KB · Affichages: 26
Dernière édition:

BOISGONTIER

XLDnaute Barbatruc
Repose en paix
-Comment générer une liste indentée à partir d'une BD
-Comment générer une BD à partir d'une liste indentée
-Comment afficher l'organigramme d'une BD
-Filtrer un niveau d'indentation

http://boisgontierjacques.free.fr/pages_site/listes_cascade.htm#Indent

http://boisgontierjacques.free.fr/fichiers/DonneesValidation/BDGenereIndentation.xls
http://boisgontierjacques.free.fr/fichiers/DonneesValidation/IndentGenereBD.xls
http://boisgontierjacques.free.fr/fichiers/Cellules/MasqueIndent.xls

Pour masquer/démasquer un niveau au double-clic

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  If Not Intersect([A2:A1000], Target) Is Nothing And Target.Count = 1 And Target <> "" Then
    niveau = Target.IndentLevel
    masque = Not Target.Offset(1, 0).EntireRow.Hidden
    i = 1
    Do While Target.Offset(i).IndentLevel > niveau: i = i + 1: Loop
    If i > 1 Then Target.Offset(1).Resize(i - 1).EntireRow.Hidden = masque: Target.Interior.ColorIndex = IIf(masque, 4, 2)
  End If
  Cancel = True
End Sub


Boisgontier
 

Pièces jointes

  • IndentGenereBD.xls
    43.5 KB · Affichages: 12
  • BDGenereIndentation.xls.xlsm
    55.1 KB · Affichages: 15
Dernière édition:

job75

XLDnaute Barbatruc
Bonjour Hélène B., chris, JHA, JB, le forum,

Dans le fichier joint le double-clic permet d'afficher ou masquer les indentations supérieures :
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, [B:B]) Is Nothing Then Exit Sub
Dim P As Range, IL%, tout As Boolean
Set P = Intersect(Target(2).Resize(Rows.Count - Target.Row), Target.CurrentRegion)
If P Is Nothing Then Exit Sub
Cancel = True
IL = Target.IndentLevel
If Target.HorizontalAlignment = xlCenter Then tout = True
Target.Interior.ColorIndex = IIf(Target.Interior.ColorIndex = 6, xlNone, 6)
Filtre P, IL, Target.Interior.ColorIndex = 6, tout
End Sub

Sub Filtre(P As Range, IL%, masque As Boolean, tout As Boolean)
Dim i&, plage As Range
For i = 1 To P.Rows.Count
    If Not tout Then If P(i).IndentLevel <= IL Then Exit For
    If P(i).IndentLevel > IL Then Set plage = Union(IIf(plage Is Nothing, P(i), plage), P(i))
Next
If Not plage Is Nothing Then plage.EntireRow.Hidden = masque
End Sub

Sub RAZ()
[B:B].Interior.ColorIndex = xlNone
Rows.Hidden = False
End Sub
Bon dimanche.
 

Pièces jointes

  • Indentations(1).xlsm
    25.4 KB · Affichages: 16

BOISGONTIER

XLDnaute Barbatruc
Repose en paix

Pièces jointes

  • MenuDeroulantIndentOk.xlsm
    26.5 KB · Affichages: 11
  • Indent.png
    Indent.png
    21.1 KB · Affichages: 19
  • Indent2.png
    Indent2.png
    19.6 KB · Affichages: 16
Dernière édition:

Discussions similaires

Réponses
3
Affichages
424
Réponses
5
Affichages
441