Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 190
Default sum certain columns

hi,

i have a sheet with severasl rows in it. each row corresponds to a certain
month and year. ranging from jan-04 through mar-08. i would like to add a
new column to the worksheet, and have it have a formula for the YTD sum. so
how can i make it to where the new column only adds the amounts for months in
the current year? can this be programatically done?

thanks in advance,
geebee

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default sum certain columns

geebee,

With dates in column A, and values to sum in column B, both starting in Row 2 (headers in row 1) in
C2 use the formula

=SUMPRODUCT((YEAR($A$2:$A2)=YEAR(A2))*$B$2:B2)

And then copy down to match your data set. This assumes that the dates are sorted ascending.

HTH,
Bernie
MS Excel MVP


"geebee" (noSPAMs) wrote in message
...
hi,

i have a sheet with severasl rows in it. each row corresponds to a certain
month and year. ranging from jan-04 through mar-08. i would like to add a
new column to the worksheet, and have it have a formula for the YTD sum. so
how can i make it to where the new column only adds the amounts for months in
the current year? can this be programatically done?

thanks in advance,
geebee



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default sum certain columns

This is the formula I did

=SUM(OFFSET($A$1,ROW()-1,MATCH(DATEVALUE("Jan-"&TEXT(YEAR(TODAY()),"YY")),$1:$1,1)-1,1,1):OFFSET(BA9,0,-1))

It uses cell A1 as the reference. It finds the data Jan 1 for the current
year and then adds all the data in the current row from this column to the
column - 1 where the formula is located. In my case the column for the YTD
is BA and the row it is in is row 9. This can be added via VBA

Range("BA9").formula = Myformula

where myformula is "=......." 'the formula shown above. Make sure the equal
sign is in Myformula

"geebee" wrote:

hi,

i have a sheet with severasl rows in it. each row corresponds to a certain
month and year. ranging from jan-04 through mar-08. i would like to add a
new column to the worksheet, and have it have a formula for the YTD sum. so
how can i make it to where the new column only adds the amounts for months in
the current year? can this be programatically done?

thanks in advance,
geebee

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
create a macro to delete columns and then border remaining columns Jane777 Excel Programming 1 July 18th 07 12:08 AM
Combine multiple columns into two long columns, Repeating rows in first column [email protected] Excel Discussion (Misc queries) 2 July 31st 06 09:45 PM
Combine multiple columns into two long columns, Repeating rows in first column [email protected] Excel Discussion (Misc queries) 0 July 31st 06 05:07 PM
Excel 2007 extra columns - but transposing columns still not working! [email protected] Excel Programming 0 July 26th 06 02:58 PM
Pivot Table Creating New Columns that Subtract Two Existing Columns den4673 Excel Discussion (Misc queries) 3 December 17th 04 01:31 PM


All times are GMT +1. The time now is 09:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"