Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Petit coup de main sur un code

4 réponses
Avatar
Excel...lent
Bonjour,

Ci dessous mon code

Sub M6CghtHor()
If ActiveCell.Row < 4 Or ActiveCell.Row > 7 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
If ActiveCell.Row < 10 Or ActiveCell.Row > 13 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
If ActiveCell.Row < 16 Or ActiveCell.Row > 19 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
If ActiveCell.Row < 22 Or ActiveCell.Row > 25 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
If ActiveCell.Row < 28 Or ActiveCell.Row > 31 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
If ActiveCell.Row < 34 Or ActiveCell.Row > 37 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
If ActiveCell.Row < 40 Or ActiveCell.Row > 43 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
If ActiveCell.Row < 46 Or ActiveCell.Row > 49 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
If ActiveCell.Row < 52 Or ActiveCell.Row > 55 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
If ActiveCell.Row < 58 Or ActiveCell.Row > 61 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
DEPROT_PAGE ' code de déprotection de la feuille
Selection.FormulaR1C1 = "M6"
PROT_PAGE ' code de protection de la feuille
Exit Sub

A la base ce code était comme ça :

Sub M6CghtHor()
If ActiveCell.Row < 4 Or ActiveCell.Row > 7 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
DEPROT_PAGE ' code de déprotection de la feuille
Selection.FormulaR1C1 = "M6"
PROT_PAGE ' code de protection de la feuille
Exit Sub

Alors pourquoi quand ce code est comme le basique ci-dessus il fonctionne
bien et il ne fonctionne plus quand il est comme le premier ? Je vois pas
très bien pourquoi...

Merci de votre aide.

Cordialement.

Excel...lent

4 réponses

Avatar
Daniel
Parce que si :
ActiveCell.Row > 7 : Exit Sub
ActiveCell.Row < 10 : Exit Sub
C'est à dire fin de macro dans tous les cas.
Daniel
"Excel...lent" a écrit dans le message de news:
eqZ51G%
Bonjour,

Ci dessous mon code

Sub M6CghtHor()
If ActiveCell.Row < 4 Or ActiveCell.Row > 7 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
If ActiveCell.Row < 10 Or ActiveCell.Row > 13 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
If ActiveCell.Row < 16 Or ActiveCell.Row > 19 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
If ActiveCell.Row < 22 Or ActiveCell.Row > 25 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
If ActiveCell.Row < 28 Or ActiveCell.Row > 31 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
If ActiveCell.Row < 34 Or ActiveCell.Row > 37 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
If ActiveCell.Row < 40 Or ActiveCell.Row > 43 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
If ActiveCell.Row < 46 Or ActiveCell.Row > 49 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
If ActiveCell.Row < 52 Or ActiveCell.Row > 55 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
If ActiveCell.Row < 58 Or ActiveCell.Row > 61 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
DEPROT_PAGE ' code de déprotection de la feuille
Selection.FormulaR1C1 = "M6"
PROT_PAGE ' code de protection de la feuille
Exit Sub

A la base ce code était comme ça :

Sub M6CghtHor()
If ActiveCell.Row < 4 Or ActiveCell.Row > 7 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
DEPROT_PAGE ' code de déprotection de la feuille
Selection.FormulaR1C1 = "M6"
PROT_PAGE ' code de protection de la feuille
Exit Sub

Alors pourquoi quand ce code est comme le basique ci-dessus il fonctionne
bien et il ne fonctionne plus quand il est comme le premier ? Je vois pas
très bien pourquoi...

Merci de votre aide.

Cordialement.

Excel...lent




Avatar
Excel...lent
Salut Daniel,

Bon sang mais c'est bien sur aurait dit le commisssaire bip des cinq
dernières minutes.-)))

Quel boulet je fais ! En fait tu as compris le principe du code basique :

Sub M6CghtHor()
If ActiveCell.Row < 4 Or ActiveCell.Row > 7 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
DEPROT_PAGE ' code de déprotection de la feuille
Selection.FormulaR1C1 = "M6"
PROT_PAGE ' code de protection de la feuille
Exit Sub

inscrire "M6" dans la zone de B4:G7. Ok mais ce que je souhaitais en "
bricolant " mon code basique c'était d'étendre cette fonction à d'autres
zones :

B10:G13 / B16:B19 / B22:B25 / B28:B31 / B34:B37 / B40:B43 / B46:B49 /
B52:B55 / B58:B61

Donc en dehors de ces zones point d'insertion !

Et là je seèche au soleil devant mon put... de code.

Merci de ton aide.

Cordialement.

Marc
Avatar
Yoyo
Bonsoir,

Tu peux essayer ainsi :

If Not Intersect(ActiveCell,
Union(Range("B4:G7,B10:G13,B16:B19,B22:B25,B28:B31"), _
Range("B34:B37,B40:B43,B46:B49,B52:B55,B58:B61"))) Is Nothing Then
DEPROT_PAGE ' code de déprotection de la feuille
Selection.FormulaR1C1 = "M6"
PROT_PAGE ' code de protection de la feuille
End If
Exit Sub

Amicalement



Sub M6CghtHor()
If ActiveCell.Row < 4 Or ActiveCell.Row > 7 Or ActiveCell.Column < 2 Or
ActiveCell.Column > 7 Then Exit Sub
DEPROT_PAGE ' code de déprotection de la feuille
Selection.FormulaR1C1 = "M6"
PROT_PAGE ' code de protection de la feuille
Exit Sub

inscrire "M6" dans la zone de B4:G7. Ok mais ce que je souhaitais en "
bricolant " mon code basique c'était d'étendre cette fonction à d'autres
zones :

B10:G13 / B16:B19 / B22:B25 / B28:B31 / B34:B37 / B40:B43 / B46:B49 /
B52:B55 / B58:B61


Avatar
Excel...lent
Salut Yoyo,

C'est au poil exactement ce que je recherchais. Et là franchement sans un
petit coup de main j'y serais pas arrivé tout seul.

Merci à toi.

Merci également à toi Daniel.

Cordialement.

Marc