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

Autres (RESOLU) afficher et masquer des colonnes via combobox

chaelie2015

XLDnaute Accro
Bonjour
Je souhaite afficher et masquer des colonnes via une Combobox.
Merci par avance
 

Pièces jointes

  • charlie masquer colonne par combobox.xlsm
    14.1 KB · Affichages: 7

chaelie2015

XLDnaute Accro
Bonjour,
A tester avec une macro établie au plus simple pour comprendre la manoeuvre
Re
Je souhaite ajouter a ton code ,un code de contrôle. Par exemple si je sélectionne dans combobox "masquer Cahier 1" et ces colonnes sont déjà masqué alors informer l'utilisateur par message que elles sont déjà masquées et vis versa ?
MERCI
 
Dernière édition:

job75

XLDnaute Barbatruc
Bonjour chaelie2015, M12, fanch55,

En modifiant la liste source comme le fait fanch55, une solution plus simple dans ce fichier :
VB:
Private Sub ComboBox1_Change()
Static flag As Boolean
If flag Then Exit Sub
Dim i%, col%, col3%, P As Range, cb$, test As Boolean
i = ComboBox1.ListIndex
If i = -1 Then Exit Sub
flag = True
If i < 3 Then col = Application.Match("Cahier " & i + 1, Rows(1), 0) Else col = Application.Match("Cahier 1", Rows(1), 0)
col3 = Application.Match("Cahier 3", Rows(1), 0)
Set P = IIf(i < 3, Cells(1, col).MergeArea, Range(Cells(1, col), Cells(1, col3).MergeArea))
cb = ComboBox1
With [Cahiers]
    With .Cells(i + 1)
        test = .Value Like "Masquer*"
        .Replace IIf(test, "Masquer", "Afficher"), IIf(test, "Afficher", "Masquer"), xlPart 'modifie la liste source
    End With
    If cb = "Masquer tous" Then .Replace "Masquer", "Afficher" Else If cb = "Afficher tous" Then .Replace "Afficher", "Masquer"
    If Application.CountIf(.Cells, "Afficher Cahier*") = 3 Then .Cells(4) = "Afficher tous"
    If Application.CountIf(.Cells, "Masquer Cahier*") = 3 Then .Cells(4) = "Masquer tous"
End With
ComboBox1 = cb 'restitue la valeur choisie
P.EntireColumn.Hidden = test 'masque/affiche
flag = False
End Sub
A+
 

Pièces jointes

  • charlie masquer colonne par combobox.xlsm
    25.1 KB · Affichages: 4
Dernière édition:

job75

XLDnaute Barbatruc
Dans ce fichier (2) j'ai remplacé :
VB:
    If Application.CountIf(.Cells, "Afficher Cahier*") = 3 Then .Cells(4) = "Afficher tous"
    If Application.CountIf(.Cells, "Masquer Cahier*") = 3 Then .Cells(4) = "Masquer tous"
par :
VB:
    If cb Like "Masquer*" Then .Cells(4) = "Afficher tous"
    If cb Like "Afficher*" Then .Cells(4) = "Masquer tous"
C'est plus simple en fait.

A+
 

Pièces jointes

  • charlie masquer colonne par combobox(2).xlsm
    25.1 KB · Affichages: 2

Discussions similaires

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