Masquer colonne selon variable

BRUNO62

XLDnaute Occasionnel
Bonjour,

Je souhaite masquer une ou plusieurs colonnes en fonction de variable "A" ou "B" positionner sur la ligne 2.
Ci-dessous extrait VBA
Sub A()
Dim Cel As Range
Do
Set Cel = Rows(2).SpecialCells(xlCellTypeVisible).Find("A") or Set Cel = Rows(2).SpecialCells(xlCellTypeVisible).Find("B")

If Cel Is Nothing Then
Exit Sub
Else
Columns(Cel.Column).Hidden = True
End If
Loop
End Sub
Cela ne fonctionne pas. Merci, de votre aide.
Bonne soirée.
A+
 

mapomme

XLDnaute Barbatruc
Supporter XLD
Re : Masquer colonne selon variable

Bonsoir BRUNO62,

Essayer le code suivant:
VB:
Sub Masquer()
Const Quoi = "A;B"
Dim elem, Cel As Range, adr$

  For Each elem In Split(Quoi, ";")
    Set Cel = Rows(2).Find(elem)
    If Not Cel Is Nothing Then
      adr = Cel.Address
      Do
        Cel.EntireColumn.Hidden = True
        Set Cel = Rows(2).FindNext(Cel)
      Loop Until Cel.Address = adr
    End If
  Next elem
End Sub
 

Pièces jointes

  • Bruno62-masquer colonne critères v1.xlsm
    16.3 KB · Affichages: 25
Dernière édition:

Discussions similaires

Statistiques des forums

Discussions
312 348
Messages
2 087 510
Membres
103 570
dernier inscrit
patrickb83p