XL 2016 Clôturer-This worbook vba

Keran

XLDnaute Junior
Bonjour j'aurais aimer savoir si il etais possible de faire une macro "generique" avec ma macro
VB:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim WS As Worksheet
For Each WS In Sheets(Array("Janvier", "HJanvier", "BJanvier", "Bilan"))
WS.Unprotect ("azerty")
WS.Calculate
WS.Protect ("azerty"), DrawingObjects:=True, Contents:=True, Scenarios:=True _
                       , AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True, AllowFiltering:=True
Next WS
End Sub
Pour dans l'idee faire comme mais en worksheet change et non active
VB:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Dim Cel As Range
Application.ScreenUpdating = False
With Sh
    If .Name = "B" & .Range("A1") Then
        For Each Cel In Sh.Range("B8:CA8")
            If Not IsError(Cel) Then Cel.EntireColumn.Hidden = Cel = ""
        Next Cel
    End If
End With
Application.ScreenUpdating = True
End Sub

merci d'avance
 

Keran

XLDnaute Junior
Je voulais faire une fonction du genre mais je pense me tromper
VB:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim WS As Worksheet
With Sh
For Each WS In Sheets(Array(Sh, ("H" & Sh), ("B" & Sh), "Bilan"))
    If .Name = .Range("A1") Then
WS.Unprotect ("azerty")
WS.Calculate
WS.Protect ("azerty"), DrawingObjects:=True, Contents:=True, Scenarios:=True _
                       , AllowFormattingCells:=True, AllowFormattingColumns:=True, AllowFormattingRows:=True, AllowFiltering:=True


        For Each Cel In Sh.Range("B8:CA8")
            If Not IsError(Cel) Then Cel.EntireColumn.Hidden = Cel = ""
        Next Cel
    End If
End With
End Sub
 

Discussions similaires

Réponses
7
Affichages
292

Statistiques des forums

Discussions
311 733
Messages
2 082 015
Membres
101 867
dernier inscrit
XFPRO