+ Reply to Thread
Results 1 to 9 of 9

Add numbers in x number of columns given specific criteria

  1. #1
    Registered User
    Join Date
    05-13-2009
    Location
    Nelspruit, South Africa
    MS-Off Ver
    Excel 2003
    Posts
    3

    Add numbers in x number of columns given specific criteria

    Hi there

    I have a workbook in Excel 2003 with two spreadsheet, a data sheet and a summary sheet. The data sheet contains account numbers in column A and monthly values from column B to M (April to March) for each account. Account numbers occur more than once in column A.

    The summary sheet contains each account number as in the data sheet, but only once with a month column and a YTD (year to date) column. Part of my function is to report on a given month number as well as a year to date number as at that given month. For example if it is May, I need to report the results for May as well as April and May totals. Cell C 1 contains the value of the particular month (say month 1 equals April and month 12 equals March).

    I need a formula or function to return the year to date results given a certain month (cell C1) for each account number. The sumif function does not help since it only returns values for 1 column. I need the formula to perform a sumif function but if I put in 2 in cell c1 I need the formula to add the values in columns B and C, if I put a 3 in cell C1 I need the formula to add the values in columns B, C and D.
    Attached Files Attached Files
    Last edited by Met Uysh!; 05-19-2009 at 02:58 AM.

  2. #2
    Forum Contributor
    Join Date
    04-16-2009
    Location
    Stellenbosch, South Africa
    MS-Off Ver
    Excel 2003; Excel 2007; Excel 2010; Excel 2013
    Posts
    136

    Re: Add numbers in x number of columns given specific criteria

    Try this in C2 and copy to end of range:

    =SUMPRODUCT((datasheet!$A$2:$A$31=$A2)*(datasheet!$B$1:$M$1<=MOD(MONTH(TODAY())+8,12)+1),datasheet!$B$2:$M$31)
    Regards

    Jon (Excel 2003, 2007, 2010, 2013)

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Add numbers in x number of columns given specific criteria

    Or alternatively:

    C2:
    =SUMPRODUCT((datasheet!$A$2:$A$31=$A2)*(datasheet!$B$2:INDEX(datasheet!$B$2:$M$31,0,$B$1)))

    Also you don't need to use an Array in B given you can use INDEX to create your one column range in a standard SUMIF:

    B2:
    =SUMIF(datasheet!$A$2:$A$31,$A2,INDEX(datasheet!$B$2:$M$31,0,$B$1))
    Last edited by DonkeyOte; 05-19-2009 at 02:37 AM. Reason: missing absolute qualifier

  4. #4
    Forum Contributor
    Join Date
    04-16-2009
    Location
    Stellenbosch, South Africa
    MS-Off Ver
    Excel 2003; Excel 2007; Excel 2010; Excel 2013
    Posts
    136

    Re: Add numbers in x number of columns given specific criteria

    Yes, I believe Donkeys' INDEX method is more efficient. You can take best from both...

    =SUMPRODUCT((datasheet!$A$2:$A$31=$A2)*(datasheet!$B$2:INDEX(datasheet!$B$2:$M$31,0,MOD(MONTH(TODAY())+8,12)+1)))

    I'm assuming you need to work out the current month, hence the MOD thingy...

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Add numbers in x number of columns given specific criteria

    Jon, I think the month is specified in B1.

  6. #6
    Forum Contributor
    Join Date
    04-16-2009
    Location
    Stellenbosch, South Africa
    MS-Off Ver
    Excel 2003; Excel 2007; Excel 2010; Excel 2013
    Posts
    136

    Re: Add numbers in x number of columns given specific criteria

    Erm, yes, ok.

    I assumed he wanted it worked out...

  7. #7
    Registered User
    Join Date
    05-13-2009
    Location
    Nelspruit, South Africa
    MS-Off Ver
    Excel 2003
    Posts
    3

    Wink Re: Add numbers in x number of columns given specific criteria

    Wow, that was quick and surely efficient!!! Thanks guys!! Although I looked at the index and sumproduct formulas before I could not understand how to use it in conjunction. I've found the formula =SUMPRODUCT((datasheet!$A$2:$A$31=$A2)*(datasheet!$B$2:INDEX(datasheet!$B$2:$M$31,0,$B$1))) to be the easiest.

    Thansk alot!!!

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Add numbers in x number of columns given specific criteria

    We're glad to have helped.

    I would advise you also alter formulae in B as suggested so as to remove the Arrays which are not necessary in this particular instance.

    Please remember to mark thread as solved (see FAQ if unsure)

  9. #9
    Registered User
    Join Date
    05-13-2009
    Location
    Nelspruit, South Africa
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Add numbers in x number of columns given specific criteria

    Thanks, I've used the Sumif as suggested for the month with the Index formula. I am really impressed, I've searched for a week and found nothing. I posted this and in no time got the solution!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1