Bonjour à tous !
Je viens vers vous car j'ai rédigé une macro sur VBA pour un problème à priori tout bête. Sur le papier j'ai l'impression que tout est bon, mais ça ne fonctionne malheureusement pas. Malheureusement, je n'arrive pas à identifier le problème. Du coup je fais appel à vous. J'espère que vous pourrez m'aider.
En gros, j'ai un fichier Excel qui se présente comme suit :
Date
Nom Client
Montant hors taxes
Date début
Date Fin
Et je voudrais simplement étaler le Montant hors taxes sur toute la durée, en mois. Je joins mon fichier pour que vous ayez une meilleure idée de ce que je cherche à faire. Revenues test.xlsm
Voilà donc le code que j'ai rédigé pour ce faire :
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 Sub Monthly_Computation() nb_col = Worksheets("Past & On-going").Range("A2").End(xlToRight).Column For j = 2 To nb_col Worksheets("Past & On-going").Columns(j).Activate Total = Selection.Range("A7").Value - Selection.Range("A6").Value + 1 nb_first = 31 - Day(Selection.Range("A6")) + 1 nb_last = Day(Selection.Range("A7")) Month_last = Month(Selection.Range("A7")) If Year(Selection.Range("A7")) = Year(Selection.Range("A6")) + 1 Then Month_last = Month(Selection.Range("A7")) + 12 End If nb_inter = Month_last - Month(Selection.Range("A6")) - 1 For i = 1 To 12 If Month(Selection.Range("A6")) = i Then first_amnt = (nb_first / Total) * Selection.Range("A5").Value Selection.Range("A" & 11 + i).Value = first_amnt End If If Month(Selection.Range("A7")) = i Then last_amnt = (nb_last / Total) * Selection.Range("A5").Value Selection.Range("A" & 11 + i).Value = last_amnt End If Next i rest = Selection.Range("A5").Value - first_amnt - last_amnt For k = 1 To 12 If Month(Selection.Range("A6")) + nb_inter = k Then If rest > 1 Then Selection.Range("A" & 11 + k).Value = rest / nb_inter If nb_inter > 1 Then For l = Month(Selection.Range("A6")) + 1 To Month(Selection.Range("A6")) + nb_inter - 1 Selection.Range("A" & 11 + l).Value = rest / nb_inter Next l End If End If End If Next k Next j End Sub
En outre, la macro me renvoie "Overflow" et ne s'execute pas entièrement quand je lance ma procédure. Pourtant, ce n'est pas un programme très compliqué ou long...
Voilà, je crois que j'ai tout dit. Si vous avez des conseils ou une idée pour arranger mes problèmes, vous me sauveriez !!
N'hésitez pas si vous avez des questions, ce n'est peut-être pas très clair...
Merci mille fois par avance !
Partager