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

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:

fanch55

XLDnaute Barbatruc
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 .... ;)
 

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
151

Statistiques des forums

Discussions
312 094
Messages
2 085 240
Membres
102 832
dernier inscrit
kirale