+ Reply to Thread
Results 1 to 9 of 9

Arrays and Collections and Dictionaries oh my

  1. #1
    Forum Contributor
    Join Date
    08-25-2014
    Location
    Pennsylvania, US
    MS-Off Ver
    Windows '16
    Posts
    165

    Arrays and Collections and Dictionaries oh my

    Hi everyone. I hope you can give me some high-level guidance on something I'm working on. I'm beginning to learn VBA for Excel and have a specific problem I wish to solve (/ dynamic workbook I want to make) in mind. Part of the workbook will involve taking a list of stock tickers, their associated name, sector, and subsector and putting it in a list somewhere else. For example three lines of data are

    AMZN Amazon.com, Inc. Consumer Discretionary Internet & Catalog Retail
    KO Coca-Cola Company Consumer Staples Beverages
    XOM Exxon Mobil Corporation Energy Oil Gas & Consumable Fuels

    There are more than 500 rows like that ^ and they change every once in a while. The first two columns never repeat, while the third and fourth (sector and subsector) repeat often.

    I would like to make lists, for example, of everything in Consumer Discretionary. And separately, everything in Beverages. And separately, everything in Oil Gas & Consumable Fuels. My question is what is the best way to implement this?

    I've been reading a lot about potential different ways to do this and don't know which will make my life hardest/toughest. Considering the data (e.g. the values in each row will always be associated with each other), should I use...
    • A 2D array?
    • A collection?
    • A dictionary?
    • A 1D array with a user-defined type that includes four strings?
    • Something else?

    I can upload a workbook if you want, but I'm not expecting too much code, if any, in an answer. Let me know if you need more information. Thanks

    EDIT: I should clarify that the length and members of all the lists are variable. (Depends on the original list from which everything else is derived...)
    Last edited by JYTS; 12-22-2015 at 03:14 AM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523

    Re: Arrays and Collections and Dictionaries oh my

    Attaching a sample workbook enables others to work on your problem:

    To attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include BEFORE/AFTER sheets if needed to show the process you're trying to complete or automate. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

    To add a file to a new post

    To add a file to an existing post.

  3. #3
    Forum Contributor
    Join Date
    08-25-2014
    Location
    Pennsylvania, US
    MS-Off Ver
    Windows '16
    Posts
    165

    Re: Arrays and Collections and Dictionaries oh my

    Hi Dave, I attached a workbook - hopefully it doesn't confuse you more. The results are sorted either alphabetically of alphabetically by subsector, which is what I intended to do after getting the data into an array/collection/dictionary.... Let me know what questions you have.

    Thanks!

    JYTS question.xlsx

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Arrays and Collections and Dictionaries oh my

    Why not just autofilter?
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Forum Contributor
    Join Date
    08-25-2014
    Location
    Pennsylvania, US
    MS-Off Ver
    Windows '16
    Posts
    165

    Re: Arrays and Collections and Dictionaries oh my

    Autofilter the UI function or autofilter the VBA method?

    Wouldn't I need a separate list for each and every output I want? The real input is 3x longer, and there are >=40 lists of outputs... Also, I would like to do some things with the data, like a list of everything, but when the sector changes skip two cells (when the subsector changes, skip one cell), etc. I *think* loading everything into memory is the way to go....

    Overall though, I'm trying to learn what is the best use for arrays vs collections vs dictionaries in general. Thanks
    Last edited by JYTS; 12-22-2015 at 12:34 PM.

  6. #6
    Forum Contributor
    Join Date
    08-25-2014
    Location
    Pennsylvania, US
    MS-Off Ver
    Windows '16
    Posts
    165

    Re: Arrays and Collections and Dictionaries oh my

    double posted can't delete

  7. #7
    Forum Contributor
    Join Date
    08-25-2014
    Location
    Pennsylvania, US
    MS-Off Ver
    Windows '16
    Posts
    165

    Re: Arrays and Collections and Dictionaries oh my

    Can anyone give some guidance?

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Arrays and Collections and Dictionaries oh my

    You could record a macro using autofilter and autofilter's sorting method. Filter, sort, copy to another sheet, unfilter, filter by something else, sort, copy, ... until you have all of the data you want.

  9. #9
    Valued Forum Contributor
    Join Date
    12-22-2015
    Location
    HK
    MS-Off Ver
    2010
    Posts
    532

    Re: Arrays and Collections and Dictionaries oh my

    Just for your reference:

    Please Login or Register  to view this content.

+ 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. Creating Dictionary of Dictionaries
    By Dodo123 in forum Excel Programming / VBA / Macros
    Replies: 32
    Last Post: 03-02-2014, 11:30 AM
  2. [SOLVED] Looking for online learning materials on arrays & scripting dictionaries
    By strud in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-11-2013, 08:16 AM
  3. Collections within class module collections
    By AndyLitch in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-14-2013, 06:00 AM
  4. Multiple Dictionaries Or One Dictionary
    By goss in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-15-2012, 07:58 AM
  5. Creating find and replace dictionaries
    By SlipperyPete in forum Excel General
    Replies: 1
    Last Post: 12-15-2006, 11:54 AM
  6. Trouble with Arrays / Collections
    By John in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-07-2005, 03:05 PM
  7. VBA - Collections/Arrays/Sorting
    By William Benson in forum Excel General
    Replies: 5
    Last Post: 05-31-2005, 10:05 AM
  8. Dictionaries for grouping
    By Piotr in forum Excel General
    Replies: 2
    Last Post: 05-23-2005, 07:06 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