Cacher / afficher si

Bonjour le Forum,

Voilà d'habitude j'utilise une macro pour afficher et cacher des données sur des lignes (j'utilise ce code qu'une collègue m'a donnée pour afficher et cacher sur des lignes :

Private Sub CheckBox1_Click()

Application.ScreenUpdating = False

Application.Calculation = xlCalculationManual

Dim Na As Integer

Dim i As Integer

If CheckBox1.Value = True Then

Na = Range("B1:B750").Rows.Count

For i = 1 To Na + 1

If Range("B1:B850").Rows(i).Value = "X" Then

Range("B1:B850").Rows(i).Select

Selection.EntireRow.Hidden = True

End If

Next i

Else

Columns(1).Select

Selection.EntireRow.Hidden = False

End If

Application.ScreenUpdating = True

Application.Calculation = xlCalculationAutomatic

End Sub

Par contre pour le fichier en pièce jointe j'aurai besoin de modifier le code pour pouvoir le mettre sur les colonnes (je voudrai masquer les colonnes ou il y a un "X". Pouvez vous m'expliquer l'astuce SVP

Je vous remercie

++

26fichier-rh.xlsm (35.63 Ko)

Bonjour Maëva, bonjour le forum,

Essaie comme ça :

Private Sub CheckBox1_Click()
Dim I As Integer

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
If CheckBox1.Value = True Then
    For I = 6 To 66
        If Cells(6, I).Value = "X" Then
            Columns(I).Hidden = True
        End If
    Next I
Else
    Cells.EntireColumn.Hidden = False
End If
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub

Super ça fonctionne !!!

merci ThauThème

Bonjour,

Sans boucle :

Sub Cacher()

    Worksheets("dossier 1").Rows(6).Cells.SpecialCells(xlCellTypeConstants).EntireColumn.Hidden = True

End Sub

Sub Afficher()

    Worksheets("dossier 1").Rows(6).Cells.SpecialCells(xlCellTypeConstants).EntireColumn.Hidden = False

End Sub

Bonjour le fil, le forum,

Beaucoup mieux !... Je l'ai toujours dit : "un pro Theze"... Bon, c'est vrai, lui il en a marre de la vanne pourrie...

Bonjour Tout le monde, salut Tauthème,

Non, ça va en attendant d'en avoir une

Rechercher des sujets similaires à "cacher afficher"