Problème pour déprotéger ma feuille via une macro
Re....
ça fait beaucoup aujourd'hui. Je vous sollicite beaucoup.
voila mon nouveau problème.
j'ai plusieurs feuilles où je peux exécuter des macros (tout en sachant que les feuilles sont protégées). Ces macros fonctionnent.
En faisant simple, les macros servent à copier des infos d'une feuille pour aller les coller sur une autre.(elles sont au nombre de 10 feuilles = 10 macros)
Je voudrais lancer ces macros avec 1 seul bouton dans une feuille à part
voila ma macro
Sub macro()
Call ExportTotalLeadsBDUTOP
Call ExportTotalLeadsBDUAcuStar
End Sub
sauf que j'ai un message d'erreur comme quoi ma cellule est protégée et qu'il faut que j'ôte la protection.
pourtant en lançant individuellement les macros ça fonctionne.
D'où vient le problème?
Merci
Pour l'aide
voici l'une des macros elles ont toutes dans le même style
Dim Sites(21, 4000)
Dim Actual(21, 4000)
Dim ILProjects(21, 4000)
Dim Nbunits(21, 4000)
Dim Cash(21, 4000)
Dim PandEMonths(21, 4000)
Dim Success(21, 4000)
Dim Instruments(21, 4000)
Dim PandE(21, 4000)
Dim Dpt(21, 4000)
Dim City(21, 4000)
Dim U As Integer
Dim W As Integer
Dim X As Integer
Dim Y As Integer
Dim Z As Integer
Sub ExportTotalLeadsBDUTOP()
Lignes = 4000
l = 1
'ActiveSheet.Unprotect ("Fcst")
'lecture données
For i = 2 To Lignes
If Sheets("Export").Range("B" & i).Formula = "Hemostasis" Then
If Sheets("Export").Range("U" & i).Formula = "Ouvert" Then
If Left(Sheets("Export").Range("M" & i), 7) = "ACL TOP" Then
If Sheets("Export").Range("T" & i).Formula > 25 Then
With Sheets("Export")
Sites(1, l) = .Range("F" & i).Value
Actual(2, l) = .Range("AD" & i).Value
ILProjects(3, l) = .Range("M" & i).Value
Nbunits(4, l) = .Range("N" & i).Value
Cash(5, l) = .Range("Q" & i).Value
PandEMonths(6, l) = .Range("R" & i).Value
Success(7, l) = .Range("T" & i).Value
Instruments(8, l) = .Range("X" & i).Value
PandE(9, l) = .Range("Y" & i).Value
Dpt(10, l) = .Range("H" & i).Value
City(11, l) = .Range("G" & i).Value
l = l + 1
End With
End If
End If
End If
End If
Next i
'écriture données
With Sheets(" Leads in Progress TOP")
U = 10
W = 10
X = 10
Y = 10
Z = 10
ActiveSheet.Unprotect ("Fcst")
For i = 1 To l
.Range("C" & i + 9).Value = Sites(1, i)
.Range("F" & i + 9).Value = Actual(2, i)
.Range("G" & i + 9).Value = ILProjects(3, i)
.Range("I" & i + 9).Value = Nbunits(4, i)
.Range("K" & i + 9).Value = Cash(5, i)
.Range("L" & i + 9).Value = PandEMonths(6, i)
.Range("M" & i + 9).Value = Success(7, i)
.Range("N" & i + 9).Value = Instruments(8, i)
.Range("O" & i + 9).Value = PandE(9, i)
.Range("B" & i + 9).Value = Dpt(10, i)
.Range("E" & i + 9).Value = City(11, i)
Next i
'Mise en forme
Application.CutCopyMode = False
Range("A10").Copy
Do While Cells(U, 2) <> ""
Cells(U, 1).Select
ActiveSheet.Paste
U = U + 1
Loop
Range("A10:U10").Copy
Do While Cells(W, 2) <> ""
Cells(W, 1).Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
W = W + 1
Loop
Application.CutCopyMode = False
Range("H10").Copy
Do While Cells(X, 2) <> ""
Cells(X, 8).Select
ActiveSheet.Paste
X = X + 1
Loop
Application.CutCopyMode = False
Range("J10").Copy
Do While Cells(Y, 2) <> ""
Cells(Y, 10).Select
ActiveSheet.Paste
Y = Y + 1
Loop
Application.CutCopyMode = False
Range("Q10:U10").Copy
Do While Cells(Z, 2) <> ""
Cells(Z, 17).Select
ActiveSheet.Paste
Z = Z + 1
Loop
Application.CutCopyMode = False
Range("I8").Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R10C9:R609C9)"
Range("J8").Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R10C10:R609C10)"
Range("K8").Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R10C11:R609C11)"
Range("L8").Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R10C12:R609C12)"
Range("Q8").Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R10C17:R609C17)"
Range("R8").Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R10C18:R609C18)"
Range("S8").Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R10C19:R609C19)"
Range("T8").Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R10C20:R609C20)"
Range("U8").Select
ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R10C21:R609C21)"
End With
ActiveSheet.Protect ("Fcst")
End Sub
Bonsoir,
Un exemple à tester et à adapter à ton environnement.
Avec 1 seul bouton, mettre en début de code, "Déprotéger" et en fin de code "Protéger".
Avec l'hypothèse d'un mot de passe unique.
Ces 2 procédures doivent être placées dans le même module que ta procédure principale.
Cdlt.
Option Explicit
Private Sub Déprotéger()
Dim Ws As Worksheet
Application.ScreenUpdating = False
For Each Ws In ActiveWorkbook.Worksheets
Ws.Unprotect Password:="jep"
Next
End Sub
Private Sub Protéger()
Dim Ws As Worksheet
Application.ScreenUpdating = False
For Each Ws In ActiveWorkbook.Worksheets
Ws.Protect Password:="jep"
Next
End Sub
encore merci Jean Eric ta macro fonctionne.
Par contre. la macro que j'ai créé comme ci dessus ne fonctionne plus. elle effectue bien le copier coller d'une feuille à l'autre mais ne prend pas en compte la mise en forme tu sais pourquoi ?
bonjour,
j'ai réussi à me sortir de mon problème.
Merci encore à Jean Eric.