Pb macro vérouillage feuille

lioneldu47

XLDnaute Occasionnel
Bonjour le forum,​
J'ai un petit problème de macro que je n'arrive pas à résoudre... pourtant j'ai vu plus compliqué mais il y a toujours un débogage que je ne comprend pas.

Voici la macro que je voudrais modifier :

Private Sub CmbValiderretrait_Click()
ActiveSheet.Unprotect
Dim L As Long, x As Long
L = ComboRef.ListIndex + 2
If TextQuantité1 = "" Then
MsgBox " Vouse devez définir une quantité"
Exit Sub
End If
If IsNumeric(TextQuantité1) = False Then
MsgBox " Vous devez définir une quantité numérique"
Exit Sub
End If

With Sheets("Stock")

x = .Cells(L, 4) - CLng(TextQuantité1.Value)
If x < 0 Then
MsgBox "La quantité n'est pas disponible"
TextQuantité1 = ""
TextQuantité1.SetFocus
Exit Sub
End If

End With

With Sheets("Stock")

.Cells(ComboRef.ListIndex + 2, 4) = .Cells(ComboRef.ListIndex + 2, 4) - CLng(TextQuantité1.Value)
If .Cells(ComboRef.ListIndex + 2, 13) >= .Cells(ComboRef.ListIndex + 2, 4) Then
UserForm2.Show
End If
End With
Unload Me
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub


La feuille stock est vérouillé donc la macro ne fonctionne pas. Je sais qu'il faut insérer: ActiveSheet.Unprotect et ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Mais je ne dois pas mettre ces bout de macro au bon endroit.

Merci pour votre aide.:)
 

Sly le globe trotter

XLDnaute Occasionnel
Re : Pb macro vérouillage feuille

Salut Lioneldu47,

Pense à utiliser les balises de code ;)

En procédant de la sorte, cela devrait fonctionner...
Code:
Private Sub CmbValiderretrait_Click()
ActiveSheet.Unprotect
Dim L As Long, x As Long
L = ComboRef.ListIndex + 2
If TextQuantité1 = "" Then
MsgBox " Vouse devez définir une quantité"
Exit Sub
End If
If IsNumeric(TextQuantité1) = False Then
MsgBox " Vous devez définir une quantité numérique"
Exit Sub
End If

With Sheets("Stock")

x = .Cells(L, 4) - CLng(TextQuantité1.Value)
If x < 0 Then
MsgBox "La quantité n'est pas disponible"
TextQuantité1 = ""
TextQuantité1.SetFocus
Exit Sub
End If

End With

With Sheets("Stock")
[COLOR="Red"]Sheets("Stock").unprotect[/COLOR]

.Cells(ComboRef.ListIndex + 2, 4) = .Cells(ComboRef.ListIndex + 2, 4) - CLng(TextQuantité1.Value)
If .Cells(ComboRef.ListIndex + 2, 13) >= .Cells(ComboRef.ListIndex + 2, 4) Then
UserForm2.Show
End If
End With
Unload Me
[COLOR="Red"]Sheets("Stock").Protect DrawingObjects:=True, Contents:=True, Scenarios:=True[/COLOR]
End Sub
 

Paritec

XLDnaute Barbatruc
Re : Pb macro vérouillage feuille

Bonjour Lionel le forum
tu as mis activesheet.unprotect oui mais lorsque tu cliques sur ton bouton quelle feuille est active?
si c'est pas la feuille souhaité c'est normal cela ne marche pas.
encore une fois si tu avais joint ton fichier on aurait modifié directement
a+
Papou :)

EDIT: Bonjour Sky et le premier bout de la macro il tourne avec quoi? là cela ne marche toujours pas pour moi !!!
 
Dernière édition:

Statistiques des forums

Discussions
312 582
Messages
2 089 951
Membres
104 314
dernier inscrit
Tuubibumi