Extraction d'un montant à partir d'une date

Fermé
Maxime_86 Messages postés 35 Date d'inscription mercredi 17 avril 2013 Statut Membre Dernière intervention 11 avril 2017 - Modifié le 27 mars 2017 à 13:27
Maxime_86 Messages postés 35 Date d'inscription mercredi 17 avril 2013 Statut Membre Dernière intervention 11 avril 2017 - 11 avril 2017 à 12:10
Bonjour,

Je débute en VB et j'ai un problème par rapport à une date donc j'ai un tableau de 3 dimensions et je veux en extraire le total d'un montant à partir de mes dates, le tableau est le suivant :

|01.01.2015|31.01.2015| 1564.00|
|01.02.2015|28.02.2015| 2576.00|
|01.03.2015|31.03.2015| 2852.00|
|01.01.2015|31.01.2015| 5495.25|
|01.02.2015|28.02.2015| 9051.00|
|01.03.2015|31.03.2015| 10020.75|
|01.04.2015|25.04.2015| 8081.25|
|10.05.2016|20.05.2016| 0.00|
|10.05.2016|20.05.2016| 0.00|
|21.05.2016|28.05.2016| 2611.84|

Ma première colonne de tableau est mappé sur une variable que j'ai nommé D_VS_TAB_REG_DEB_PERIOD_REG
ma deuxième colonne D_VS_TAB_REG_FIN_PERIOD_REG
et ma troisième colonne D_VS_TAB_REG_MONT_REG

le but est de calculer la somme de mon montant à partir d'une période.
si l'utilisateur choisis la période du 01.02.2015(variable:D_VS_DATE_DEBUT) au 01.04.2015( D_VS_DATE_FIN) je devrai avoir le cumul de 2576.00 + 2852.00 + 9051.00 + 10020.75 + 8081.25 en sortit j'utilise ce code là mais ça ne marche pas.

DIM i AS Integer
DIM k AS Integer
DIM j AS Integer
FOR i = 1 to Count(D_VS_TAB_REG_DEB_PERIOD_REG)
IF(D_VS_TAB_REG_DEB_PERIOD_REG(i) < D_VS_DATE_DEBUT) THEN
k=i+1
ENDIF
NEXT
FOR j = 1 to Count(D_VS_TAB_REG_FIN_PERIOD_REG)
IF(D_VS_TAB_REG_FIN_PERIOD_REG(j) < D_VS_DATE_FIN) THEN
j=j+1
ENDIF
value = Sum(D_VS_TAB_REG_MONT_REG,k,j)
NEXT

c'est normal que ça ne marche pas car quand mon code rencontre une date inférieur dans la suite il décrémente mon indice.

auriez vous une solution à mon problème?

Merci.

2 réponses

Maxime_86 Messages postés 35 Date d'inscription mercredi 17 avril 2013 Statut Membre Dernière intervention 11 avril 2017 1
27 mars 2017 à 14:52
sinon j'ai utilisé ce code qui marche très bien, sauf que le compte est limité à 10 vu qu'il n'y a pas de boucle :

DIM a AS INTEGER
DIM b AS INTEGER
DIM c AS INTEGER
DIM d AS INTEGER
DIM e AS INTEGER
DIM f AS INTEGER
DIM g AS INTEGER
DIM h AS INTEGER
DIM l AS INTEGER
DIM m AS INTEGER

a = D_VS_TAB_REG_MONT_REG(1)
b = D_VS_TAB_REG_MONT_REG(2)
c = D_VS_TAB_REG_MONT_REG(3)
d = D_VS_TAB_REG_MONT_REG(4)
e = D_VS_TAB_REG_MONT_REG(5)
f = D_VS_TAB_REG_MONT_REG(6)
g = D_VS_TAB_REG_MONT_REG(7)
h = D_VS_TAB_REG_MONT_REG(8)
l = D_VS_TAB_REG_MONT_REG(9)
m = D_VS_TAB_REG_MONT_REG(10)

if ((D_VS_TAB_REG_DEB_PERIOD_REG(1)<D_VS_DATE_DEBUT) or (D_VS_TAB_REG_FIN_PERIOD_REG(1) > D_VS_DATE_FIN))then
a = 0
endif
if ((D_VS_TAB_REG_DEB_PERIOD_REG(2)<D_VS_DATE_DEBUT) or (D_VS_TAB_REG_FIN_PERIOD_REG(2) > D_VS_DATE_FIN))then
b = 0
endif
if ((D_VS_TAB_REG_DEB_PERIOD_REG(3)<D_VS_DATE_DEBUT) or (D_VS_TAB_REG_FIN_PERIOD_REG(3) > D_VS_DATE_FIN))then
c = 0
endif
if ((D_VS_TAB_REG_DEB_PERIOD_REG(4)<D_VS_DATE_DEBUT) or (D_VS_TAB_REG_FIN_PERIOD_REG(4) > D_VS_DATE_FIN))then
d = 0
endif
if ((D_VS_TAB_REG_DEB_PERIOD_REG(5)<D_VS_DATE_DEBUT) or (D_VS_TAB_REG_FIN_PERIOD_REG(5) > D_VS_DATE_FIN))then
e = 0
endif
if ((D_VS_TAB_REG_DEB_PERIOD_REG(6)<D_VS_DATE_DEBUT) or (D_VS_TAB_REG_FIN_PERIOD_REG(6) > D_VS_DATE_FIN))then
f = 0
endif
if ((D_VS_TAB_REG_DEB_PERIOD_REG(7)<D_VS_DATE_DEBUT) or (D_VS_TAB_REG_FIN_PERIOD_REG(7) > D_VS_DATE_FIN))then
g = 0
endif
if ((D_VS_TAB_REG_DEB_PERIOD_REG(8)<D_VS_DATE_DEBUT) or (D_VS_TAB_REG_FIN_PERIOD_REG(8) > D_VS_DATE_FIN))then
h = 0
endif
if ((D_VS_TAB_REG_DEB_PERIOD_REG(9)<D_VS_DATE_DEBUT) or (D_VS_TAB_REG_FIN_PERIOD_REG(9) > D_VS_DATE_FIN))then
l = 0
endif
if ((D_VS_TAB_REG_DEB_PERIOD_REG(10)<D_VS_DATE_DEBUT) or (D_VS_TAB_REG_FIN_PERIOD_REG(10) > D_VS_DATE_FIN))then
m = 0
endif
value = a + b + c + d + e + f + g + h + l + m
0
michel_m Messages postés 16603 Date d'inscription lundi 12 septembre 2005 Statut Contributeur Dernière intervention 16 décembre 2023 3 303
30 mars 2017 à 09:03
bonjour

Pas besoin de VBA pour traiter ce problàme avec un SOMMEPROD (xL<2007) ou SOMME.SI.ENS (xl>=2007)
0
Maxime_86 Messages postés 35 Date d'inscription mercredi 17 avril 2013 Statut Membre Dernière intervention 11 avril 2017 1
11 avril 2017 à 12:10
Bonjour,

Je ne bosse pas sur exel donc je suis obligé d'utiliser VBA.

Merci.
0