+ Reply to Thread
Results 1 to 9 of 9

sum multiple values in a dictionary by key name

  1. #1
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    sum multiple values in a dictionary by key name

    Hi all, I've set up a multi-dimensional dictionary, there my main dictionary is "kids".
    Then the keys in there, are the names of the kids, let's say "JOE", "PETE", "MARY" and "SUE".
    Now each of these kids names are actually another dictionary with details, so each kid has different attributes.

    Example
    DICT - VALUE - DICT - VALUE
    KIDS - JOE - AGE - 8
    KIDS - JOE - MARBLES - 12
    KIDS - PETE - PET - GOLDFISH
    KIDS - PETE - SIBLINGS - 2
    KIDS - MARY - AGE - 10
    KIDS - MARY - MARBLES - 9
    KIDS - MARY - PET - DOG
    KIDS - SUE - MARBLES - 7
    KIDS - SUE - PET - CAT
    KIDS - SUE - SIBLINGS 0

    now I can find out Joe's age by saying:
    DEBUG.PRINT KIDS("JOE")("AGE")
    or Mary's pet by saying:
    DEBUG.PRINT KIDS("MARY")("PET")

    and that works fine.
    But I want to figure out how many marbles they have combined.
    So essentially:
    KIDS(ALL_OF_THEM)("MARBLES")

    Can that be done without looping through them?

    Thanks!

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: sum multiple values in a dictionary by key name

    Put simply, no, you need to look don't worry though it's quick, not like looking through a worksheet

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: sum multiple values in a dictionary by key name

    *loop grrr autocorrect

  4. #4
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: sum multiple values in a dictionary by key name

    I was afraid of that - thanks though!

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: sum multiple values in a dictionary by key name

    No worries mate, you finished thimbleweed yet?

  6. #6
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: sum multiple values in a dictionary by key name

    Not yet - I think I'm halfway through. Really forgot how time consuming games like these are (compared to the usual 30mins of Counterstrike I play nowadays).

    Another question on dictionaries, if I may.
    I set up a dictionary of dictionaries for example like this:

    DICTIONARY: "KIDS"
    DICTIONARY: "KIDS-STUFF" (containing: "AGE", "PET", "MARBLES" etc)
    VARIABLE: "JOE" (or "PETE", "SUE" etc)

    So I say:
    Kids.Add "Joe", KIDS-STUFF

    But is there any way to add two variables into this?
    So for example adding their last name as a variable
    Kids.Add "Joe", "Palmer", KIDS-STUFF ?

    Where Joe and Palmer should be flexible?
    I don't think there is, cause I'd have to pre-define the last name as a dictionary again, but just checking if I'm overlooking something.

  7. #7
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: sum multiple values in a dictionary by key name

    No, you can't do that. I suspect that you may be better off with classes than Dictionaries of Dictionaries - they'll give you more flexibility

    Are you running 32 bit or 64 bit Excel (not windows)?

  8. #8
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: sum multiple values in a dictionary by key name

    Both - this is for a tool that's shared across different windows and excel versions. I'm not well versed in class modules though, so you'd have to walk me through it.
    Is it better if I send you a PM / email or start another thread?

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: sum multiple values in a dictionary by key name

    Start a new thread mate, would be useful to get some background too as to what you're actually doing

+ 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. Retrieving values from dictionary
    By badeye in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-30-2016, 05:45 AM
  2. [SOLVED] Dictionary or Scripting.Dictionary. Binding Referencing Dim-ing. Sub routines and Function
    By Doc.AElstein in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 07-12-2016, 08:28 AM
  3. [SOLVED] vba - dictionary to sumif values
    By michiel soede in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-26-2015, 03:30 PM
  4. Dictionary - Using a dictionary of dictionaries to hold individual orders
    By wazimu13 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-09-2015, 08:32 PM
  5. Dictionary key made up of multiple values/criteria?
    By ColdDay in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-15-2014, 12:29 PM
  6. Help using Scripting Dictionary to sum values
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 08-09-2014, 04:15 PM
  7. Add Unique Values to Dictionary
    By mccrimmon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-30-2011, 07:05 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