Private Sub CommandButton1_Click() Application.ScreenUpdating = False Application.Calculation = xlCalculationManual USFwait.Show 0 USFwait.Repaint etat = False For i = 2 To 7 Sheets(i).Activate Sheets(i).Unprotect Password:="Toto" voyons Sheets(i).Range("K4:K100"), "---", bouton, True Sheets(i).Protect Password:="Toto" Next Worksheets(1).Activate Application.Calculation = xlAutomatic Application.ScreenUpdating = True Unload USFwait End Sub
Private Sub Workbook_Open() Set bouton = Sheets(1).CommandButton1 etat = False For i = 2 To 7 voyons Sheets(i).Range("K4:K100"), "---", bouton, False Next If etat Then bouton.Caption "montrer" Else bouton.Caption "cacher" With Worksheets("Total") .EnableAutoFilter = True .EnableOutlining = True .Protect Contents:=True, Password:="Indiko", UserInterfaceOnly:=True End With End Sub
Public atraiter As Range, bouton As Object, etat As Boolean Public Sub voyons(plage As Range, quoi As String, bouton As Object, how As Boolean) Dim i As Long, tablo Set atraiter = Nothing If WorksheetFunction.CountIf(plage, quoi) > 0 Then tablo = plage For i = 1 To UBound(tablo) If tablo(i, 1) = quoi Then If plage(i).EntireRow.Hidden True Then etat True If atraiter Is Nothing Then Set atraiter = plage(i) Else Set atraiter = Union(atraiter, plage(i)) End If End If Next End If If etat Then bouton.Caption "cacher" Else bouton.Caption "montrer" If Not how Then Exit Sub If Not atraiter Is Nothing Then atraiter.EntireRow.Hidden = Not etat End If End Sub
J'ai testé ton code, ça fonctionne nickel et c'est hyper rapide...
Par contre un truc bizarre ma Feuil2 n'est pas pris en compte.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub Workbook_Open() tab1(0, 0) = "Total" tab1(0, 1) = "K14:K63" tab1(1, 0) = "Réactifs" tab1(1, 1) = "K14:K64" tab1(2, 0) = "Calibrateurs" tab1(2, 1) = "K14:K93" tab1(3, 0) = "Contrôles" tab1(3, 1) = "K14:K75" tab1(4, 0) = "Accessoires Indiko" tab1(4, 1) = "K14:K44" tab1(5, 0) = "Prix Patient" tab1(5, 1) = "K14:K63" Set bouton = Sheets(1).CommandButton1 etat = False For i = 0 To 5 voyons Sheets(tab1(i, 0)).Range(tab1(i, 1)), "---", bouton, False '====>>> remplkace ici par ta chaîne à toi Next If etat Then bouton.Caption "montrer" Else bouton.Caption "cacher" With Worksheets("Total") .EnableAutoFilter = True .EnableOutlining = True .Protect Contents:=True, Password:="Indiko", UserInterfaceOnly:=True End With End Sub
Private Sub CommandButton1_Click() Application.ScreenUpdating = False Application.Calculation = xlCalculationManual USFwait.Show 0 USFwait.Repaint etat = False For i = 0 To 5 Sheets(tab1(i, 0)).Activate Sheets(tab1(i, 0)).Unprotect Password:="Indiko" voyons Sheets(tab1(i, 0)).Range(tab1(i, 1)), "---", bouton, True Sheets(tab1(i, 0)).Protect Password:="Indiko" Next Worksheets(1).Activate Application.Calculation = xlAutomatic Application.ScreenUpdating = True Unload USFwait End Sub