+ Reply to Thread
Results 1 to 6 of 6

Calculate the sum of a column if the month and year is correct.

  1. #1
    Registered User
    Join Date
    06-17-2014
    Location
    Uppsala, Sweden
    MS-Off Ver
    2010
    Posts
    43

    Calculate the sum of a column if the month and year is correct.

    So yesterday I created a thread (http://www.excelforum.com/excel-prog...ng-column.html) that would clear a specific content if a date (or rather a day) matched the criteria. (I got helped by TMS and diberlee with a nice macro that helped me with that.)


    Today I'm continuing with that document and need to sum the columns if the date in a row is the correct month and year.

    Ex. Row 1 contains the date "yyyy-mm-dd" and row 2-5 contains empty cells or the value x. The x values are all random placed.

    So, I want to sum all the "x" for februari 2014.

    I'd rather use a formula here than a macro/VBA-code but anything will do. I have tried myself with =sumifs and =sumproduct but with no sucess.

    See attached file for example and for my =sumproduct formula.

    Thanks in advance
    /Johan
    Attached Files Attached Files
    Last edited by johansoder; 06-19-2014 at 08:53 AM.

  2. #2
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Calculate the sum of a column if the month and year is correct.

    You were so close
    =SUMPRODUCT((YEAR(B1:U1)=2014)*(MONTH(B1:U1=1)*(B2:U5="x")))
    should be
    =SUMPRODUCT((YEAR(B1:U1)=2014)*(MONTH(B1:U1)=1)*(B2:U5="x"))

  3. #3
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Calculate the sum of a column if the month and year is correct.

    Hi Johansoder

    Your formula is correct, except you missed to insert a closed bracket for the month context



    Your Formula {SUMPRODUCT((YEAR(B1:U1)=2014)*(MONTH(B1:U1=1)*(B2:U5="x"))}

    Revised Formula { SUMPRODUCT((YEAR(B1:U1)=2014)*(MONTH(B1:U1)=1)*(B2:U5="x"))}

    Hope this helps

    Cheers
    Don't forget to rate 1 who helped u, using "Star"

  4. #4
    Registered User
    Join Date
    06-17-2014
    Location
    Uppsala, Sweden
    MS-Off Ver
    2010
    Posts
    43

    Re: Calculate the sum of a column if the month and year is correct.

    Wow I was close..

    But thanks alot for the answers guys, will give rep. I also noticed I calculated for Januari instead of Februari (if anyone gets confused about the month=1 instead of =2).

  5. #5
    Forum Contributor
    Join Date
    01-03-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2016,Excel 2013
    Posts
    186

    Re: Calculate the sum of a column if the month and year is correct.

    No worries. Please change the status to "Solved" if you are happy.

    Thanks

  6. #6
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Calculate the sum of a column if the month and year is correct.

    You're welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] I have the day and month but not the Year-need a macro to calculate the Year
    By iplayball in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-31-2013, 01:31 AM
  2. If Column A Month and Year = ColumnB Todays Month and Year then send email
    By HACCStaff in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-15-2013, 12:47 AM
  3. Need VBA to add month/year column and delete month/year column
    By MrsGarrett in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-20-2012, 07:12 PM
  4. Replies: 1
    Last Post: 08-13-2012, 11:18 AM
  5. to calculate this month, this year, last year figure
    By mingali in forum Excel General
    Replies: 7
    Last Post: 08-07-2010, 03:22 AM

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