XL 2016 Format cellule Gras VBA

medsoft313

XLDnaute Nouveau
Bonjour à tous,
J'ai un fichier Excel en VBA protéger par mot de passe, la plupart des cellules sont verrouillé sauf la plage E20:E48 de ma feuille.
J'aimerais que utilisateur puisse mettre le texte écrit dans cette plage en gras cette option est facultatif.
J'ai trouvé ce code
Worksheets("Sheet1").Range("E20:E48").Font.Bold = True
mais le problème et que le format de la plage se transforme en gras dès l'écriture alors que moi je veux cette option est facultatif.
Merci d'avance.
 
Solution
Bonjour medsoft313, Jacky67,

Voyez le fichier joint et ces 2 macros avec leurs raccourcis clavier :
VB:
Sub Gras()
'raccourci clavier Ctrl+g
With Sheets("Feuil1")
    If ActiveSheet.Name <> .Name Then Exit Sub
    If Intersect(ActiveCell, .[E20:E48]) Is Nothing Then Exit Sub
    .Protect "toto", UserInterfaceOnly:=True
    ActiveCell.Font.Bold = True
End With
End Sub

Sub NonGras()
'raccourci clavier Ctrl+G
With Sheets("Feuil1")
    If ActiveSheet.Name <> .Name Then Exit Sub
    If Intersect(ActiveCell, .[E20:E48]) Is Nothing Then Exit Sub
    .Protect "toto", UserInterfaceOnly:=True
    ActiveCell.Font.Bold = False
End With
End Sub
A+

medsoft313

XLDnaute Nouveau
Comment exécuter ce code dans Worksheet_Activate()
VB:
Sub Gras()
'raccourci clavier Ctrl+g
With Sheets("Feuil1")
    If ActiveSheet.Name <> .Name Then Exit Sub
    If Intersect(ActiveCell, .[E20:E48]) Is Nothing Then Exit Sub
    .Protect "toto", UserInterfaceOnly:=True
    ActiveCell.Font.Bold = True
End With
End Sub
 

Discussions similaires

Réponses
12
Affichages
568

Statistiques des forums

Discussions
312 215
Messages
2 086 330
Membres
103 187
dernier inscrit
ebenhamel