+ Reply to Thread
Results 1 to 18 of 18

SumProduct help

  1. #1
    Registered User
    Join Date
    03-14-2007
    Posts
    47

    SumProduct help

    Hi i have a formula im using, =SUMPRODUCT(H10:H200="Yes")--(MONTH(J10:J200)=M2)

    what im trying to do is if the range of h10:h200 has a yes in and the month of the range in the same row of dates from j10:j200 is this month then to sum the total

    but cant seem to get it working, M2 is a cell where i have the formula =Month(M1)
    and M1=Today()

    how would i do this?

    thanks

  2. #2
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: SumProduct help

    Hi,

    You nearly got it - just a couple of little tweaks:

    Please Login or Register  to view this content.
    Hope that helps,

    Colin

    RAD Excel Blog

  3. #3
    Registered User
    Join Date
    03-14-2007
    Posts
    47

    Re: SumProduct help

    thanks very much worked a treat

  4. #4
    Registered User
    Join Date
    03-14-2007
    Posts
    47

    Re: SumProduct help

    one more question about this, i would like the cell m1 which is =Today()
    once its updated to todays date, to not change again and be locked at that date

  5. #5
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: SumProduct help

    Hi,

    TODAY() is a volatile function so it will automatically update whenever the sheet is recalculated. Your only option would be to copy --> pastespecial values (ie. hard code) the date.

  6. #6
    Registered User
    Join Date
    03-14-2007
    Posts
    47

    Re: SumProduct help

    i cant upload the workbook as its over the filesize rules, is there anyway i can datestamp the cell when a new sheet is created based on that months date?i have a button where it creates a new worksheet and names it based on a month:

    Please Login or Register  to view this content.
    and then a cell where it has the formula =MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,256)

    and that determines the month and name of the sheet, is there anyway where at the moment the Cell O1 and O2 has the formulas =TODAY() and =MONTH(O1) and then possibly not have O2 update automatically?
    cheers
    Last edited by NBVC; 02-04-2011 at 11:07 AM.

  7. #7
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: SumProduct help

    Please remember to use code tags around any code snippets next time.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  8. #8
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: SumProduct help

    Sure, if you're using VBA then it should be quite easy to put the current month in the cell when you create the worksheet. For example:

    Please Login or Register  to view this content.
    Hope that helps...

  9. #9
    Registered User
    Join Date
    03-14-2007
    Posts
    47

    Re: SumProduct help

    thanks colin, how would i incorporate the code that i have with the code that you have, so that the code you have also copies the sheet and creates a new one named the month based on the code you've wrote?

  10. #10
    Registered User
    Join Date
    03-14-2007
    Posts
    47

    Re: SumProduct help

    i suppose what im trying to ask is where would the code
    ActiveSheet.Copy Sheets(Sheets.Count)
    go to copy the sheet that is active before its created and renamed based on the month?

    thanks again, im not good with VBA

  11. #11
    Registered User
    Join Date
    03-14-2007
    Posts
    47

    Re: SumProduct help

    another question, sorry to be a pain....how do i then for the cell "m2" use that as a date for my formulas where i have the month e.g february as a number "2"

  12. #12
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: SumProduct help

    Hi,
    another question, sorry to be a pain....how do i then for the cell "m2" use that as a date for my formulas where i have the month e.g february as a number "2"
    If you want 2 in the cell instead of February, just change this line:
    Please Login or Register  to view this content.
    to this:
    Please Login or Register  to view this content.
    Does that help?

  13. #13
    Registered User
    Join Date
    03-14-2007
    Posts
    47

    Re: SumProduct help

    Yeah that helps but now i need the cell "m2" to show 2 and the sheet name to show february?

  14. #14
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: SumProduct help

    Hi,

    VBA.Date() is a function that returns today's date.

    VBA.Month() is a function that returns the month (as an integer) of a given date, so VBA.Month(VBA.Date) would return 2.

    VBA.MonthName() is a function that returns a string indicating the specified month, so VBA.MonthName(VBA.Month(VBA.Date)) would return "February" on my computer.

    Hopefully that makes it clearer how we get the two things you need:

    Please Login or Register  to view this content.

    The next thing you need to think about is duplicate worksheet names. If someone generates the new worksheet twice in the same month, or after 12 months have passed, you will get an error?

  15. #15
    Registered User
    Join Date
    03-14-2007
    Posts
    47

    Re: SumProduct help

    All done sorry colin,
    i used a bit of initiative

    Sub AddSheet()

    Dim wstNew As Worksheet
    Dim strThisMonth As String
    Dim strmonthname As String

    strThisMonth = VBA.Month(VBA.Date)

    strmonthname = VBA.MonthName(VBA.Month(VBA.Date))
    Set wstNew = Worksheets.Add(after:=Worksheets(Worksheets.Count))

    wstNew.Name = strmonthname
    wstNew.Range("M2").Value = strThisMonth


    End Sub

    but how do i get it to copy the sheet that is currently active and then do the above code?

  16. #16
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: SumProduct help

    but how do i get it to copy the sheet that is currently active and then do the above code?
    Try this:
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    03-14-2007
    Posts
    47

    Re: SumProduct help

    thank you very much colin, your a legend, with this of course i assume the sheetname cannot be duplicated and the sheetname will only change for the new sheet as long as its a new month

  18. #18
    Registered User
    Join Date
    03-14-2007
    Posts
    47

    Re: SumProduct help

    thanks again colin, another question, im using the =SUMPRODUCT(--(C10:C200="Value"),--(H10:H200<>""),--(MONTH(H10:H200)=O2))
    In one of the formulas for a cell, obviously O2=the month of that worksheet name as discussed above, what i would like for it to do is if the sheet for the month before has a cell with a date which is equal to this months date then to be included within this months total aswell,
    e.g if januarys sheet has a cell which is a date in february, then on february =SUMPRODUCT(--(C10:C200="Mortgage"),--(H10:H200<>""),--(MONTH(H10:H200)=O2)) total to be included within that even though its on januarys worksheet
    any help would be great again

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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