View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
macropod macropod is offline
external usenet poster
 
Posts: 329
Default sum x number of fields containing data

Hi Tammy,

Assuming you have multiple prior years' dates in A1:A5000 of a sheet named 'PriorYears', with the values in the corresponding cells
in Column B, this year's dates are in ColumnA of your worksheet of interest, then the following array formula will do the job:
=SUM(IF((YEAR(PriorYears!A$1:A$5000)+1=YEAR(A1))*( MONTH(PriorYears!A$1:A$5000)=MONTH(A1))*(DAY(Prior Years!A$1:A$5000)<=DAY(A1)),PriorYears!B$1:B$5000) )

If you only have last year's data in a sheet named 'LastYear', then the following array formula will do the job:
=SUM(IF((MONTH(LastYear!A$1:A$366)=MONTH(A1))*(DAY (LastYear!A$1:A$366)<=DAY(A1)),LastYear!B$1:B$366) )

Insert whichever version of the formula you need on your first data row, change the worksheet name ('PriorYears'/'LastYear') and the
range references to suit your needs (eg you'll need to have the formula start at row 2 if row 1 is a header row), then copy down as
far as needed.

Note: As these are array formulae, you'll need to press 'Ctrl-Shift-Enter' when you input them, instead of just 'Enter'.

Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------

"Tammy" wrote in message ...
I'm trying to make a spreadsheet that compares month to date sales figures to
previous years. How can I reference a field that says how many business days
have passed in the current month, and have THAT number of fields, containing
data, total from another page? i.e. -- If this is the 6th business day of
the month, how can I have the sheet to total the first 6 fields that have
data from last year? (The history sheet contains blank fields for days of
the month that were not business days.)