lundi 4 juin 2018

For/While cycle with double condition in excel

I have a list with date intervals and currency conversions associated to those intervals. See example below:

Start Date  Close Date  EUR
30/03/2013  26/04/2013  1.18
30/03/2013  26/04/2013  1.18
27/04/2013  24/05/2013  1.19
25/05/2013  28/06/2013  1.17
29/06/2013  26/07/2013  1.17
27/07/2013  23/08/2013  1.16
24/08/2013  27/09/2013  1.16 
28/09/2013  25/10/2013  1.19
26/10/2013  22/11/2013  1.17
23/11/2013  27/12/2013  1.2
28/12/2013  24/01/2014  1.2
05/01/2014  21/02/2014  1.21
22/02/2014  28/03/2014  1.21
29/03/2014  25/04/2014  1.21
26/04/2014  23/05/2014  1.21
04/05/2014  27/06/2014  1.24
08/06/2014  25/07/2014  1.25
26/07/2014  22/08/2014  1.26
23/08/2014  25/09/2014  1.25
26/09/2014  23/10/2014  1.28

I need to convert each date interval into single lines including all possible dates within the interval, and keep the respective conversion rates. So for the first date interval it would be:

30/03/2013  1.18
31/03/2013  1.18
01/04/2013  1.18
02/04/2013  1.18
03/04/2013  1.18
04/04/2013  1.18
05/04/2013  1.18
06/04/2013  1.18
07/04/2013  1.18
08/04/2013  1.18
09/04/2013  1.18
10/04/2013  1.18
11/04/2013  1.18
12/04/2013  1.18
13/04/2013  1.18
14/04/2013  1.18
15/04/2013  1.18
16/04/2013  1.18
17/04/2013  1.18
18/04/2013  1.18
19/04/2013  1.18
20/04/2013  1.18
21/04/2013  1.18
22/04/2013  1.18
23/04/2013  1.18
24/04/2013  1.18
25/04/2013  1.18
26/04/2013  1.18

Is there anyway to this easily for all date ranges? I've come up with something like this in excel:

=IF(AND(A1>='Sheet1'!$A$1, A1<='Sheet1'!$B$1), 'Sheet1'!$C$1), A1=current cell containing a date; Sheet1!A1=Start Date; Sheet1!B1=Close Date; C1=EUR conversion

The problem is that I need it to move to the following row everytime the conditions don't apply. Meaning, everytime the date being analysed is outside the interval in question, I need to increase the row position by one in Sheet1. Any help would be appreciated. VBA would be fine.

Best, Antonio

Aucun commentaire:

Enregistrer un commentaire