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

aide pour une formule

2 réponses
Avatar
hys56
Bonjour je souhaiterais une aide pour cette formule
les deux premières colonnes fonctionnent ex : j'entre 100 en a10 et
j'obtiens 40
ex : j'entre
80 en b10 et j'obtiens 60
mais pas la troisième si j'entre 30 ça reste 30 Pq?
Merci de l'aide

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo FIN
Dim d As Double
If Not Intersect(Target, [A10:A25]) Is Nothing Then d = 5
If Not Intersect(Target, [b10:b25]) Is Nothing Then d = 4
If Not Intersect(Target, [A10:A25]) Is Nothing Then m = 2
If Not Intersect(Target, [b10:b25]) Is Nothing Then m = 3
If Not Intersect(Target, [c10:c25]) Is Nothing Then m = 2
Application.EnableEvents = False
If (IsNumeric(Target) And Not IsEmpty(Target)) Then Target = Target / d
If (IsNumeric(Target) And Not IsEmpty(Target)) Then Target = Target * m

FIN:
Application.EnableEvents = True
End Sub

2 réponses

Avatar
Fdecourt
Salut,

C'est normal, cela renvoit une erreur. La division par 0 n'est pas
possible.
Dans ton troisième cas, m = 2 mais d = 0, donc le premier calcul te
renvoit forcément une erreur car Target / 0 n'est pas possible.

Pour que cela fonctionne, il faut que par defaut d soit égal à 1
(j'ai aussi enlevé If (IsNumeric(Target) And Not IsEmpty(Target)) Then
Target = Target * m)

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo FIN
Dim d As Double
d = 1
If Not Intersect(Target, [A10:A25]) Is Nothing Then d = 5
If Not Intersect(Target, [b10:b25]) Is Nothing Then d = 4
If Not Intersect(Target, [A10:A25]) Is Nothing Then m = 2
If Not Intersect(Target, [b10:b25]) Is Nothing Then m = 3
If Not Intersect(Target, [c10:c25]) Is Nothing Then m = 2
Application.EnableEvents = False
If (IsNumeric(Target) And Not IsEmpty(Target)) Then Target = (Target /
d) * m

FIN:
Application.EnableEvents = True
End Sub

Cordialement,

F.
Avatar
hys56
Bonsoir et merci bcp ça fonctionne correctement
cordialement

"Fdecourt" a écrit dans le message de news:

Salut,

C'est normal, cela renvoit une erreur. La division par 0 n'est pas
possible.
Dans ton troisième cas, m = 2 mais d = 0, donc le premier calcul te
renvoit forcément une erreur car Target / 0 n'est pas possible.

Pour que cela fonctionne, il faut que par defaut d soit égal à 1
(j'ai aussi enlevé If (IsNumeric(Target) And Not IsEmpty(Target)) Then
Target = Target * m)

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo FIN
Dim d As Double
d = 1
If Not Intersect(Target, [A10:A25]) Is Nothing Then d = 5
If Not Intersect(Target, [b10:b25]) Is Nothing Then d = 4
If Not Intersect(Target, [A10:A25]) Is Nothing Then m = 2
If Not Intersect(Target, [b10:b25]) Is Nothing Then m = 3
If Not Intersect(Target, [c10:c25]) Is Nothing Then m = 2
Application.EnableEvents = False
If (IsNumeric(Target) And Not IsEmpty(Target)) Then Target = (Target /
d) * m

FIN:
Application.EnableEvents = True
End Sub

Cordialement,

F.