Mesdames, Messieurs,

En essayant de faire une marco qui me donne simplement une soustraction de deux valeurs, un problème intervient après plusieurs itérrations. le code est somme toute assez simple car il fait un Vlookup et soustrait les valeurs trouvées:
l'erreur vient se situer avec la variable "new_price".

le voici:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
76
77
78
79
80
81
82
83
84
85
86
87
Sub emerging()
 
Dim mea As Double
Dim tur As Double
Dim sa As Double
Dim q4 As Double
Dim PN As String
Dim modifier As String
Dim plage As Range
Dim request_plage As Range
Dim new_price As Double
Dim difference As Double
Dim i As Double
 
 
 
 
For i = 0 To 50 Step 1
 
Set plage = Worksheets("approved prices").Range("A4:N296")
modifier = Worksheets("request").Cells(2, 2)
PN = Worksheets("request").Cells(i + 10, 2)
 
If IsEmpty(new_price) = False Then
new_price = Worksheets("request").Application.WorksheetFunction.VLookup(PN, plage, 6, False)
 
 
 
q4 = Worksheets("approved prices").Application.WorksheetFunction.VLookup(PN, plage, 13, False)
mea = Worksheets("approved prices").Application.WorksheetFunction.VLookup(PN, plage, 10, False)
tur = Worksheets("approved prices").Application.WorksheetFunction.VLookup(PN, plage, 11, False)
sa = Worksheets("approved prices").Application.WorksheetFunction.VLookup(PN, plage, 12, False)
 
 
 
If mea = tur = sa = 0 Then
 
difference = q4 - new_price
 
ElseIf mea > q4 And modifier = "Promotion Kuwait" Then
 
difference = mea - new_price
 
 
ElseIf mea > q4 And modifier = "Promotion Israel" Then
 
difference = mea - new_price
 
ElseIf mea > q4 And modifier = "Promotions Saudi Arabia" Then
 
difference = mea - new_price
 
ElseIf mea > q4 And modifier = "Promotions United Arab Emirates" Then
 
difference = mea - new_price
 
ElseIf tur > q4 And modifier = "promotions Turkey" Then
 
difference = tur - new_price
 
ElseIf sa > q4 And modifier = "promotion South Africa" Then
 
difference = sa - new_price
 
Else
 
difference = q4 - new_price
 
 
 
End If
Else
 
difference = 0
 
End If
 
 
difference = Worksheets("request").Cells(i + 10, "U")
 
 
 
Next i
 
 
 
End Sub
Toute aide est la bienvenue

D'avance merci.
J.A