I'm just a beginner in VBA, so it would be really nice if somebody could me help out a bit here:
I have a table with yearly sales data like:
- Year 2007: 15
- Year 2008: 20
- Year 2009: 25
- Year 2010: 30
However, it could be that an item only started selling in 2007 on September 1 (09/01/2007) and ended selling in 2010 on April 1/2010 (04/01/2010).
Now I want to calculate one overall yearly average. The way I do it is to it all by hand:
- Calculate the days the product sold in 2007 (09/01/2007 - 01/01/2007 = 243 days)
- Take the ratio (243/365 = 0,665753) and multiply that with the sales of 2007. 2008 and 2009 are full years, so both * 1. For 2010, I again calculate the ratio 0,246576 [90/365 days].
- Then I sum all these values and divide them by 2,912329 (0,665753 + 0,246575 + 1 + 1, because 2008/2009 are both full years).
It would make my life so much easier if I could give excel a date range (09/01/2007 to 04/01/2010) and it would give me the output:
0,665753 (243/365 for 2007)
1 (for full year 2008)
- 1 (for full year 2009)
- 0,246575 (ratio 90/365 for 2010)
Please see image below to make it a bit easier to understand:
