Protéger les cellule sans buguer le code

Ilino

XLDnaute Barbatruc
Bonjour Forum
Je vous soliste encore, mon souci est le suivant; âpres une longue durée de teste et des questions j’ai élaboré ce code, mais mon souci est comment faire un mot de passe a mon fichier ( verrouiller qlq cellules ) sans buger le code ci-joint le code :
Code:
Option Explicit
'Afficher ( ou masquer ) les lignes si PJ = OUI

Private Sub Worksheet_Change(ByVal Target As Range)

If Intersect(Target, [C38,C56,E56,C90,C106,C116,F116,F170,H170,C294,F294,C372,F384,C42,C414]) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Rows("40:67").Hidden = [C38] <> "Oui"
If [C56] <> "Oui" Then Rows("58:67").Hidden = True
If [E56] < 5 Then _
  Rows(68).Offset(2 * [E56] - 10).Resize(10 - 2 * [E56]).Hidden = True


Rows("78:111").Hidden = [C38] = "Pas de Jonction" Or [C38] = ""
Rows("92:95").Hidden = [C90] = "Non" Or [C90] = ""
Rows("108:111").Hidden = [C106] = "Non" Or [C106] = ""

Rows("118:157").Hidden = [C116] <> "Oui"
If [F116] < 5 Then _
  Rows(158).Offset(8 * [F116] - 40).Resize(40 - 8 * [F116]).Hidden = True
  
Rows("162:167").Hidden = [C38] = "Pas de Jonction" Or [C38] = ""

Rows("172:291").Hidden = [F170] <> "Oui"
If [H170] < 60 Then _
  Rows(292).Offset(2 * [H170] - 120).Resize(120 - 2 * [H170]).Hidden = True


Rows("296:315").Hidden = [C294] <> "Oui"
If [F294] < 10 Then _
  Rows(316).Offset(2 * [F294] - 20).Resize(20 - 2 * [F294]).Hidden = True

Target.Select 'facultatif

Rows("344:393").Hidden = [C38] = "Pas de Jonction" Or [C38] = ""


Rows("374:377").Hidden = [C372] <> "Oui"

Rows("386:393").Hidden = [F384] <> "Oui"

Rows("416:419").Hidden = [C414] <> "Oui"
End Sub
----------------------------------------------------------------------------------------
Private Sub CommandButton1_Click()
[CHAP1].ClearContents
Range("C14:G14,C28:G28,C38:D38,C42:D42,C46:G46,F58:G58,J58:N58,F60:G60,J60:N60,F62:G62,J62:N62,F64:G64,J64:N64,F66:G66,J66:N66").ClearContents
End Sub
Private Sub CommandButton2_Click()
[CHAP2].ClearContents
Range("C72:D72,C76:D76,C82:D82,C86:D86,C94:E94,G94:I94,K94:L94,C98:D98,C102:D102,C110:E110,G110:I110,K110:L110").ClearContents
End Sub
Private Sub CommandButton3_Click()
[CHAP3].ClearContents
[CHAP3BIS].ClearContents
[CHAP3BIS1].ClearContents
[CHAP3BIS2].ClearContents
Range("D118:I118,D126:I126,D134:I134,D142:I142,D150:I150,C160:D160,E164:F164,E166:F166,E164:F168,H172:P172").ClearContents
Range("H174:P174,H176:P176,H178:P178,H180:P180,H182:P182,H184:P184,H186:P186,H188:P188,H190:P190,H192:P192").ClearContents
Range("H194:P194,H196:P196,H198:P198,H200:P200,H202:P202,H204:P204,H206:P206,H208:P208,H210:P210,H212:P212").ClearContents
Range("H214:P214,H216:P216,H218:P218,H220:P220,H222:P222").ClearContents
Range("H224:P224,H226:P226,H228:P228,H230:P230,H232:P232,H234:P234,H236:P236,H238:P238,H240:P240").ClearContents
Range("H242:P242,H244:P244,H246:P246,H248:P248,H250:P250,H252:P252,H254:P254,H256:P256,H258:P258").ClearContents
Range("H260:P260,H262:P262,H264:P264,H266:P266,H268:P268,H270:P270,H272:P272,H274:P274,H276:P276,H328:I328").ClearContents
Range("H278:P278,H280:P280,H282:P282,H284:P284,H286:P286,H288:P288,H290:P290,D296:J296,D298:J298,D300:J300,D302:J302,D304:J304,D306:J306,D308:J308,D310:J310,D312:J312,D314:J314,E318:F318,F322:G322,E326:P326,K330:P330,C334:D334,F334:I334,C338:D338,E342:K342").ClearContents
End Sub
Private Sub CommandButton4_Click()
[CHAP4].ClearContents
Range("C348:D348,C356:K356,C360:D360,F360:H360,H366:J366,H368:J368").ClearContents
End Sub
Private Sub CommandButton5_Click()
[CHAP5].ClearContents
Range("C382:D382,F382:G382").ClearContents
End Sub
Private Sub CommandButton6_Click()
[CHAP6].ClearContents
Range("E398:L398,C402:D402,f402:G402,I402:L402,C404:D404,f404:G404,I404:L404,C406:D406,f406:G406,I406:L406,C408:D408,f408:G408,I408:L408,C410:D410,f410:G410,I410:L410,E414:L414").ClearContents
End Sub
grazie:confused:
 

Pierrot93

XLDnaute Barbatruc
Re : Protéger les cellule sans buguer le code

Bonjour,

par défaut toutes les cellules d'une feuille sont vérouillées, pour activer ceci il faut protéger la feuille, pour que le code puisse fonctionner sur feuille protégée, il faut que la protection soit faite par le code en utilisant l'argument "userinterfaceonly", code ci-dessous à placer dans le module "thisworkbook" :
Code:
Option Explicit
Private Sub Workbook_Open()
Sheets("Feuil1").Protect "toto", userinterfaceonly:=True
End Sub

sinon protection manuelle de la feuille => en début de procédure "unprotect" de la feuille et "protect" à la fin....
bonne soirée
@+
 

Ilino

XLDnaute Barbatruc
Re : Protéger les cellule sans buguer le code

Re pierrot
dans le meme sujet, mais cette fois je veux protéger le code vba?
j'ai fais la procédure standard ( via VBAProject-Propriétés du projet) mais ça n'a pas fonctionné?
A+
 

Statistiques des forums

Discussions
312 425
Messages
2 088 291
Membres
103 808
dernier inscrit
qsfdhqzsfg