+ Reply to Thread
Results 1 to 6 of 6

UDF that Sums based on 2 Criteria over 2 Criteria ranges

  1. #1
    Registered User
    Join Date
    12-07-2010
    Location
    Aberdeen
    MS-Off Ver
    Excel 2013
    Posts
    50

    UDF that Sums based on 2 Criteria over 2 Criteria ranges

    Can anyone tell me if it's possible to have 2 criteria and 2 different criteria ranges to sum data using a UDF.

    Sample file attached.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: UDF that Sums based on 2 Criteria over 2 Criteria ranges

    Assuming this definition:

    Please Login or Register  to view this content.
    where CellColor is criteria 1 and CoLetter is criteria 2

    and

    Please Login or Register  to view this content.
    would return 50 in your example, then:
    Please Login or Register  to view this content.
    I'm interested in starting a career working with VBA, if anyone knows of any opportunities!

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: UDF that Sums based on 2 Criteria over 2 Criteria ranges

    You only gave an example, not a specification. So here is the specification based on your example:

    Sum the numeric values in a range, including those values that have a given value in the same row immediately to the left of the sum range, and with a fill color that matches the color of a given cell.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    12-07-2010
    Location
    Aberdeen
    MS-Off Ver
    Excel 2013
    Posts
    50

    Re: UDF that Sums based on 2 Criteria over 2 Criteria ranges

    Thank you both for the quick response.

    Working a treat!

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: UDF that Sums based on 2 Criteria over 2 Criteria ranges

    Please note an important difference between the two solutions.

    walruseggman's solution assumes that you are checking column A for the letter that you want to match. That is a good solution if that is your situation. Mine is slightly more general in that it will look to the immediate left of the range containing the data. If your letters are always in column A then walruseggman's code is a bit simpler.

  6. #6
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: UDF that Sums based on 2 Criteria over 2 Criteria ranges

    Agreed, @6StringJazzer. On that note, if you do want to change the column where the company letters are, just change the 1 in Cells(myCell.Row, 1).Value to whatever you want. It's still a hard-coded column, but does offer you a degree of flexability.

    @6StringJazzer: would you care to discuss your use of myCell.Parent instead of just Cells? I'd just never seen that used before.

+ 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] Formula that sums the difference of two ranges with multiple criteria
    By kconman in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 01-08-2016, 03:55 PM
  2. Replies: 11
    Last Post: 02-12-2015, 10:44 AM
  3. Subtotals/sums based on criteria in multiple columns
    By pcaldwell in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-09-2015, 03:12 PM
  4. [SOLVED] Summing Range based on Criteria of Two Other Ranges
    By kidsick in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-14-2013, 10:35 PM
  5. VBA Code that Sums on a Loop Based on Criteria and Linked to Calender
    By mkeys4 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-24-2013, 09:15 AM
  6. Replies: 2
    Last Post: 11-06-2012, 06:40 PM
  7. Vlookup that sums multiple worksheets based on two criteria
    By jay_boogy in forum Excel Formulas & Functions
    Replies: 20
    Last Post: 12-14-2010, 12:59 PM

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