Autres (RESOLU) afficher et masquer des colonnes via combobox

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

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

Dernière édition:
Bonjour chaelie2015, M12, fanch55,

En modifiant la liste source comme le fait fanch55, une solution plus simple dans ce fichier :

A+
Salut @job75

Selon la config,
Tu as oublié l'option afficher tous
1642420246824.png


et masquer tous
1642420353117.png


Je suis le fil .... 😉
 
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

- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
6
Affichages
200
Réponses
40
Affichages
1 K
  • Question Question
Autres Code VBA
Réponses
11
Affichages
256
Retour