1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
Option Explicit
Option Base 1
Private Sub Worksheet_Change(ByVal Target As Range)
Dim x, y, i, j, k, m, leg_s As Integer
Dim tableau_R(), cell, formule As String
leg_s = leg 'leg est une variable globale qui vient d'une autre procédure
cell = Target.Address
x = 0
ReDim tableau_R(leg_s)
'je regarde combien de cellule je vais devoir surveiller.
For j = 1 To leg_s
tableau_R(j) = "$B$" & 9 + x
x = x + 21
Next
'si ces cellules change de valeur alors je prend celle qui a changé de valeur et je met les cellules correspondantes, que je dois modifier dans un tableau.
For m = 1 To leg_s
If Not Application.Intersect(Target, Range(tableau_R(m))) Is Nothing Then
ReDim tableau_P(18)
y = 0
k = 21 * m - 21
For i = 1 To 18
tableau_P(i) = "$B$" & 15 + y + k
i = i + 1
tableau_P(i) = "$C$" & 15 + y + k
i = i + 1
tableau_P(i) = "$F$" & 15 + y + k
y = y + 1
Next
Worksheets("Element").Unprotect
formule = Target.Value '''''''''''''''''''''''''''''''' mon code erreur est ici
'en fonction de se qui est dans ma cellule je modifie en conséquence toutes celles qui doivent l'être
Select Case formule
Case Is = ""
Range(tableau_P(1) & ":" & tableau_P(17) & ", " & tableau_P(3) & ":" & tableau_P(18)).Select
Selection.Locked = True
Selection.FormulaHidden = False
Case Is = "0"
Range(tableau_P(1) & ":" & tableau_P(17) & ", " & tableau_P(3) & ":" & tableau_P(18)).Select
Selection.Locked = True
Selection.FormulaHidden = False
Case Is = "1"
Range(tableau_P(1) & ":" & tableau_P(2) & ", " & tableau_P(3)).Select
Selection.Locked = False
Selection.FormulaHidden = False
Range(tableau_P(4) & ":" & tableau_P(17) & ", " & tableau_P(6) & ":" & tableau_P(18)).Select
Selection.Locked = True
Selection.FormulaHidden = False
Case Is = "2"
Range(tableau_P(1) & ":" & tableau_P(5) & ", " & tableau_P(3) & ":" & tableau_P(6)).Select
Selection.Locked = False
Selection.FormulaHidden = False
Range(tableau_P(7) & ":" & tableau_P(17) & ", " & tableau_P(9) & ":" & tableau_P(18)).Select
Selection.Locked = True
Selection.FormulaHidden = False
Case Is <> ""
Range(tableau_P(1) & ":" & tableau_P(17) & ", " & tableau_P(3) & ":" & tableau_P(18)).Select
Selection.Locked = True
Selection.FormulaHidden = False
End Select
Range(tableau_R(m)).Select
k = k + 21
Worksheets("Element").Protect DrawingObjects:=False, Contents:=True, Scenarios:=True
End If
Next |
Partager