View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default Returning data from within a date range

Cdn Fas Guy,

My Assumptions:
A1:C1 have labels, cells D1, E1, and so on to the right have dates like 11/1/2007, 12/1/2007, etc.

Cell A2 has the start date for that row (and other start dates are below)
Cell B2 has the end date for that row (and other end dates are below)
Cell C2 has the daily units for that row (and other daily units are below)

In cell D2, enter the formula (this is a long one, so remove the line breaks):

=IF(DATE(YEAR(D$1),MONTH(D$1),1)$B2,0,IF(DATE(YEA R(D$1),MONTH(D$1)+1,0)<$A2,0,IF(AND(DATE(YEAR(D$1) ,MONTH(D$1)+1,0)<$B2,DATE(YEAR(D$1),MONTH(D$1),1) $A2),$C2*DAY(DATE(YEAR(D$1),MONTH(D$1)+1,0)),IF(AN D($B2=DATE(YEAR(D$1),MONTH(D$1),1),$B2<=DATE(YEAR (D$1),MONTH(D$1)+1,0)),DAY($B2)*$C2,IF(AND($A2=DA TE(YEAR(D$1),MONTH(D$1),1),$A2<=DATE(YEAR(D$1),MON TH(D$1)+1,0)),(DAY(DATE(YEAR(D$1),MONTH(D$1)+1,0))-DAY($A2)+1)*$C2)))))/DAY(DATE(YEAR(D$1),MONTH(D$1)+1,0))

Then copy this to the right and down as far as you need.

HTH,
Bernie
MS Excel MVP


"Cdn Gas Guy" <Cdn Gas wrote in message
...
I have a list of contracts with daily volumes and dates which start and end
at various points over months/years organized in rows. Next to the this I
have columns for every calendar month moving years into the future. What I
need to do is have a formula to return the average contract volume applicable
to every given calendar month across the months.

ie. If the contract was for 30 units per day and the contract date started
Nov 30/07 then the average daily volume for Nov/07 would be 1 unit.

Any help will be greatly appreciated.