+ Reply to Thread
Results 1 to 8 of 8

Code to speed up sumproduct formulas

  1. #1
    Registered User
    Join Date
    06-27-2012
    Location
    Miami, FL
    MS-Off Ver
    Excel 2010
    Posts
    4

    Code to speed up sumproduct formulas

    Hey all,

    I am new to VBA programming so thanks for the help early on. Attached you'll find the sheet I am working with.


    I am using a sumproduct formula instead of using an array formula. The problem I am having is that the calculation process is extremely slow. I was wondering if there was a way to use VBA to look at the names on the "weekly" worksheet and then perform the sumproduct (or a formula that does the same thing) formula that is currently there.

    It could also be the formula that I am using that is causing the sheet to run so slow.

    Any help would be greatly appreciated.

    Best,
    TExcel Help.xlsx

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Code to speed up sumproduct formulas

    tbeast,

    Welcome to the forum!
    The problem is that your named ranges reference whole columns. For example, your named range "Dates" references =Data!$A:$A. That is causing the slowdown.

    I'm guessing you did this so that data could be added and the formulas would auto-update. However, you can keep that functionality without referencing the whole column by using Dynamic Named Ranges.

    So, your "Dates" named range could refer to this formula instead:
    =Data!$A$1:INDEX(Data!$A:$A,COUNTA(Data!$A:$A))

    Now the sumproduct formulas that use the "Dates" named range won't use the whole column, which should speed up their calculation considerably.

    Here's some links to more information on dynamic named ranges:
    http://support.microsoft.com/kb/830287
    http://office.microsoft.com/en-us/ex...001126115.aspx
    http://www.contextures.com/xlNames01.html
    http://www.cpearson.com/excel/DefinedNames.aspx
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    06-27-2012
    Location
    Miami, FL
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Code to speed up sumproduct formulas

    Wow, awesome!

    Thanks so much!!

  4. #4
    Registered User
    Join Date
    06-27-2012
    Location
    Miami, FL
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Code to speed up sumproduct formulas

    One last question,

    when I add that formula in the name manager, all the sumproducts return as #VALUE.

    additionally, if I like to a cell with that formula it also returns #VALUE.

    Am I doing something wrong?

  5. #5
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Code to speed up sumproduct formulas

    tbeast,

    Attached is a modified version of your posted workbook.
    I updated all of the named range formulas.
    I noticed that the ranges on the 'Data' sheet had some blank cells, so I based on the row count for all named ranges on 'Data' column A, so that they would all have the same row count as the named range "Dates". This was necessary because Sumproduct multiplies arrays together, and the arrays must have the same row count or the formula will return an error.

    I also turned the calculation mode to automatic. Changing the week beginning or week ending sees the whole table on the 'Weekly' sheet get updated basically instantly.
    Attached Files Attached Files

  6. #6
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Code to speed up sumproduct formulas

    Also, as a side note, because you're using a .xlsx file, you could replace all of your sumproduct() formulas with Sumif() formulas.

    So instead of:
    Please Login or Register  to view this content.

    It would be:
    Please Login or Register  to view this content.

    Sumifs is optimized better and doesn't calculate like an array formula, so it would also serve to speed up calculation time. However, sumifs is not backwards compatible, so the formula would return a #NAME error for any user with Excel 2003 and lower.

  7. #7
    Registered User
    Join Date
    06-27-2012
    Location
    Miami, FL
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Code to speed up sumproduct formulas

    Thank you for all your help tigeravatar.


    I'm voting you for the next Nobel Peace Prize.

  8. #8
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Code to speed up sumproduct formulas

    lol, you're very welcome

+ 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