+ Reply to Thread
Results 1 to 7 of 7

SUMPRODUCT Macro, Excel 2007 Help

  1. #1
    Registered User
    Join Date
    07-19-2010
    Location
    Greenville, SC
    MS-Off Ver
    Excel 2003
    Posts
    3

    SUMPRODUCT Macro, Excel 2007 Help

    Hello excel experts,
    I was wondering if someone could point me in the right direction on an issue I am having with an excel formula.

    Please Login or Register  to view this content.

    Here is some sample data that I want to select in the above formula:
    TestCompany, Late load - More than 2 hours late unless first stop, 2hrs
    TestCompany, Late load - More than 2 hours late unless first stop, 4hrs
    TestCompany, Late load - More than 2 hours late unless first stop, 6hrs

    This however is also getting selected:
    TestCompany, AnyValueHere, 2hrs

    For lack of a better way of describing it I’ll use SQL syntax:
    Please Login or Register  to view this content.
    Any help would be greatly appreciated.
    Cheers!
    Last edited by edgewild; 07-20-2010 at 08:52 AM. Reason: Updated Title

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,427

    Re: SUMPRODUCT Macro, Excel 2007 Help

    @edgewild

    Please post a sample spreadsheet with your data, formulae and a description of what you get (as opposed to what you want)

    Thanks

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

    Re: SUMPRODUCT Macro, Excel 2007 Help

    You need to be careful when conducting ORs in Arrays / Sumproducts by virtue of addition...

    Either:

    =SUMPRODUCT(--(Data!A2:A1000=A8),--(Data!B2:B1000="Late load - More than 2 hours late unless first stop"),--ISNUMBER(SEARCH({"2 hrs","4 hrs","6 hrs"},Data!C2:C1000)))

    or

    =SUMPRODUCT(--(Data!A2:A1000=A8),--(Data!B2:B1000="Late load - More than 2 hours late unless first stop"),(Data!C2:C1000="2 hrs")+(Data!C2:C1000="4 hrs")+(Data!C2:C1000="6 hrs"))

    The problem you have with the existing approach is that your text test in B is being used as part of the OR test, ie:

    (B=text)+(C=x)+(C=y)+(C=z)

    meaning that should C = x/y/z then irrespective of whether or not B=text the row will be counted.... you would also be at risk of double counting the row wherever B=text and C = x/y/z given you would end up with a multiple of 2 rather than 1.

    On an aside... there's no need for INDIRECT given the sheet reference is fixed - using it will make the SUMPRODUCT Volatile and generally speaking Volatile Arrays / Sumproducts are best avoided whenever/wherever possible.

  4. #4
    Registered User
    Join Date
    07-19-2010
    Location
    Greenville, SC
    MS-Off Ver
    Excel 2003
    Posts
    3

    Thumbs up Re: SUMPRODUCT Macro, Excel 2007 Help

    Quote Originally Posted by DonkeyOte View Post
    =SUMPRODUCT(--(Data!A2:A1000=A8),--(Data!B2:B1000="Late load - More than 2 hours late unless first stop"),(Data!C2:C1000="2 hrs")+(Data!C2:C1000="4 hrs")+(Data!C2:C1000="6 hrs"))
    Thank-you very much your solution is 100% on the mark. The reason I was using the INDIRECT function is because the record set, on the "data" worksheet, is perodically deleted causing the #REF error to appear in my formulas, in place of the referenced cells, when the workbook automatically recalculated.

    Again thank-you for such a well explained solution!
    Last edited by edgewild; 07-20-2010 at 09:14 AM.

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

    Re: SUMPRODUCT Macro, Excel 2007 Help

    No need to quote prior posts in your reply - simply clutters your thread.

    Quote Originally Posted by edgewild
    The reason I was using the INDIRECT function is because the record set, on the "data" worksheet, is perodically deleted causing the #REF error to appear in my formulas, in place of the referenced cells, when the workbook automatically recalculated.
    If the "Data" sheet itself is not physically deleted you can still avoid the Volatility by virtue of INDEX

    Please Login or Register  to view this content.
    As long as the sheet itself is never physically removed the above will continue to reference whatever ends up in A2:C1000 regardless of row/column deletions etc.

  6. #6
    Registered User
    Join Date
    07-19-2010
    Location
    Greenville, SC
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: SUMPRODUCT Macro, Excel 2007 Help

    Quote Originally Posted by DonkeyOte View Post

    Please Login or Register  to view this content.
    Thanks again. I'll update my formulas accordingly to use INDEX vs. INDIRECT.

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

    Re: SUMPRODUCT Macro, Excel 2007 Help

    I should make the point that using INDEX in this context is regarded as Semi-Volatile in so far as it will act as though Volatile when the file is initially opened (ie will calculate) but will cease to be Volatile thereafter.

    For more info. on Volatility and optimisation be sure to follow the link in my thread to Charles Williams' (invaluable) site ... well worth a read through as and when you have the time / inclination.

+ 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