+ Reply to Thread
Results 1 to 10 of 10

Sum value of cells based on different array values

  1. #1
    Registered User
    Join Date
    07-30-2007
    Posts
    14

    Sum value of cells based on different array values

    Hello again, everyone.

    I have a sheet that I'm trying to generate a total on, but I'm having a time trying to figure out how to do it.

    On this sheet, I have several rows of cells, one for a given employee. Each row is 30 cells long. In each of these cells, a "code" is entered (A, B, C, or D). Each code has a different point value associated with it that can vary depending on the month. There is a second sheet where I have two columns setup (B:C); the first being the code and the second being the value. What I want to do on the first sheet is have a cell on each row that gives a "point total" based on the codes entered.

    For example, A=1, B=2, C=3, D=10. Employee Tom has codes A, A, A, A, B, B, A, D, A in his row thus far. The total should show 19.

    I know this can be done with arrays, but everything I've tried just returns the result of the first cell in the row and not ALL of the cells.

    Any help on this would be very much appreciated!
    Last edited by bryceowen; 11-26-2014 at 04:56 PM.

  2. #2
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: Sum value of cells based on different array values

    LOOKUP can help

  3. #3
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,816

    Re: Sum value of cells based on different array values

    Tell us which columns are used to hold those codes - is it column B to column AD?

    Pete

  4. #4
    Registered User
    Join Date
    07-30-2007
    Posts
    14

    Re: Sum value of cells based on different array values

    The columns with the codes and values are B and C respectivly. (Column A is used to describe the codes purpose.)

  5. #5
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,816

    Re: Sum value of cells based on different array values

    I meant the codes on the first sheet you describe. Attach a sample workbook, so we can see for ourselves.

    Pete

  6. #6
    Registered User
    Join Date
    07-30-2007
    Posts
    14

    Re: Sum value of cells based on different array values

    example.xlsx
    Here's an example workbook. The 'points' column on the first worksheet is what I'm trying to populate. I was able to accomplish this with a ridiculously long sum statement with a countif for each of the day's cells, but that's a lot of extra text that I really don't want/need. I'm sure there's a much simpler function.

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,816

    Re: Sum value of cells based on different array values

    Yu can have this formula in B3:

    =COUNTIF(C3:AF3,"A")*VLOOKUP("A",Formulas!B:C,2,0)+COUNTIF(C3:AF3,"B")*VLOOKUP("B",Formulas!B:C,2,0)+COUNTIF(C3:AF3,"C")*VLOOKUP("C",Formulas!B:C,2,0)+COUNTIF(C3:AF3,"D")*VLOOKUP("D",Formulas!B:C,2,0)

    then copy down, although I'm sure that can be shortened further.

    Hope this helps.

    Pete

  8. #8
    Valued Forum Contributor
    Join Date
    07-29-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003/Excel 2010
    Posts
    534

    Re: Sum value of cells based on different array values

    Alternatively in B3:
    =SUMPRODUCT((C3:AF3=Formulas!$B$2:$B$5)*(Formulas!$C$2:$C$5))

  9. #9
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Sum value of cells based on different array values

    This is what I came up with

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    If you use named ranges:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Both are confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer. Press F2 on that cell and try again.

    These formulae will work even if the letters are determined by formula and errors occur.
    Last edited by newdoverman; 11-26-2014 at 04:37 PM.
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  10. #10
    Registered User
    Join Date
    07-30-2007
    Posts
    14

    Re: Sum value of cells based on different array values

    Thank you all for your input! Wher, your solution worked best for me (and allows me to easily add additional codes on the formulas page).

+ 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. vba macro filter based on a array of cells with text and number values
    By daviddg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2014, 04:39 AM
  2. Create an array based off values in another array - exclude blanks
    By clifton1230 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-05-2013, 05:35 PM
  3. Replies: 5
    Last Post: 04-01-2012, 02:48 AM
  4. Replies: 0
    Last Post: 03-22-2012, 03:08 PM
  5. Extracting cells from one array based on cells in another array
    By JPKenny in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-02-2010, 03:08 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