Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

bug dans ma macro worksheet_deactivate

3 réponses
Avatar
magic-dd
bonsoir

ca bug dans ma macro suivante

Private Sub Worksheet_Deactivate()
Application.EnableEvents = False
ActiveSheet.Unprotect

With Range("A5:AY50")
.Sort Key1:=Range("AY5"), _
Order1:=xlAscending, _
Key2:=Range("AX5"), _
Order2:=xlDescending, _
Header:=xlYes
End With
ActiveSheet.Protect
Application.EnableEvents = True

End Sub


je voudrais proteger ma feuille lorsque je la desactive et la
reproteger quand je l'active

sa bug au niveau du .sort

pour l'activation de la feuille j'ai ca mais la protection ne marche
pas

Private Sub Worksheet_Activate()
ActiveSheet.Unprotect
'Application.EnableEvents = False

Columns("B:B").EntireColumn.AutoFit
With Range("A5:AY50")
.Sort Key1:=Range("A5"), _
Order1:=xlAscending, _
Header:=xlYes
End With
'Application.EnableEvents = True
ActiveSheet.Protect


merci de votre aide car la je nage

3 réponses

Avatar
Daniel.C
Bonsoir.
Remplace "ActiveSheet" par Sheets("NomDeLaFeuille")
Daniel

bonsoir

ca bug dans ma macro suivante

Private Sub Worksheet_Deactivate()
Application.EnableEvents = False
ActiveSheet.Unprotect

With Range("A5:AY50")
.Sort Key1:=Range("AY5"), _
Order1:=xlAscending, _
Key2:=Range("AX5"), _
Order2:=xlDescending, _
Header:=xlYes
End With
ActiveSheet.Protect
Application.EnableEvents = True

End Sub


je voudrais proteger ma feuille lorsque je la desactive et la
reproteger quand je l'active

sa bug au niveau du .sort

pour l'activation de la feuille j'ai ca mais la protection ne marche
pas

Private Sub Worksheet_Activate()
ActiveSheet.Unprotect
'Application.EnableEvents = False

Columns("B:B").EntireColumn.AutoFit
With Range("A5:AY50")
.Sort Key1:=Range("A5"), _
Order1:=xlAscending, _
Header:=xlYes
End With
'Application.EnableEvents = True
ActiveSheet.Protect


merci de votre aide car la je nage


Avatar
michdenis
Bonjour,

Quand tu mets du code dans un module feuille,
au lieu d'utiliser "ActiveSheet" ou worksheets("NomFeuille")
Utilise tout simplement Me qui désigne la feuille dans lequel
le code est situé.

'-------------------------------------
Private Sub Worksheet_Deactivate()

Application.EnableEvents = False
Me.Unprotect

With Range("A5:AY50")
.Sort Key1:=Range("AY5"), _
Order1:=xlAscending, _
Key2:=Range("AX5"), _
Order2:=xlDescending, _
Header:=xlYes
End With
Me.Protect
Application.EnableEvents = True

End Sub
'-------------------------------------




"magic-dd" a écrit dans le message de groupe de discussion :

bonsoir

ca bug dans ma macro suivante

Private Sub Worksheet_Deactivate()
Application.EnableEvents = False
ActiveSheet.Unprotect

With Range("A5:AY50")
.Sort Key1:=Range("AY5"), _
Order1:=xlAscending, _
Key2:=Range("AX5"), _
Order2:=xlDescending, _
Header:=xlYes
End With
ActiveSheet.Protect
Application.EnableEvents = True

End Sub


je voudrais proteger ma feuille lorsque je la desactive et la
reproteger quand je l'active

sa bug au niveau du .sort

pour l'activation de la feuille j'ai ca mais la protection ne marche
pas

Private Sub Worksheet_Activate()
ActiveSheet.Unprotect
'Application.EnableEvents = False

Columns("B:B").EntireColumn.AutoFit
With Range("A5:AY50")
.Sort Key1:=Range("A5"), _
Order1:=xlAscending, _
Header:=xlYes
End With
'Application.EnableEvents = True
ActiveSheet.Protect


merci de votre aide car la je nage
Avatar
magic-dd
Merci pour l'astuce du Me

je ne connaissais pas

ca allege le code en clarté

merci

Quand tu mets du code dans un module feuille,
au lieu d'utiliser "ActiveSheet" ou worksheets("NomFeuille")
Utilise tout simplement Me qui désigne la feuille dans lequel
le code est situé.