+ Reply to Thread
Results 1 to 5 of 5

Comparing values in collections

  1. #1
    Forum Contributor
    Join Date
    12-06-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    201

    Comparing values in collections

    This is probably a stupid question but got some writers block or something.

    Got two collections:
    colPrices has share prices and the key of the collection is a share code.
    colShares has a number of shares held and the key of the collection is also the share code.

    The two collections might not be in the same order (although they probable will be) but they will have the same number of elements. So each share code will be in each collection.

    Want to iterate through the Prices collection and find any entries with a 0 price then look in the Shares collection if there is a value > 0 there for the same share. How do I get the value of the key from one collection so I can use it to look in the other collection for the same key (code)?

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

    Re: Comparing values in collections

    You can't, it's not possible to retrieve the keys of a collection, for that you need to use a dictionary object. Having said that, wouldn't it just be easier to have a single collection with each element having 2 properties, number of shares and value? That way, you would only need a single iteration

  3. #3
    Forum Contributor
    Join Date
    12-06-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: Comparing values in collections

    How do you get more values for each key in a collection? I thought you can only have one value with each key.

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

    Re: Comparing values in collections

    You can, but that value doesn't have to be just a number or a string, it could be an array or a class for example. Consider:
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    12-06-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: Comparing values in collections

    Problem solved with a third collection with only the share codes. Then used this collection to iterate and compare the values in the other two collections.
    Please Login or Register  to view this content.
    And it doesn't matter in what order any of the collections are. It uses the right one.

+ 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. Collections within class module collections
    By AndyLitch in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-14-2013, 06:00 AM
  2. [SOLVED] Collections and controls
    By montanaheather in forum Word Formatting & General
    Replies: 13
    Last Post: 12-12-2012, 09:20 AM
  3. Areas collections
    By busdani in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-09-2009, 11:50 AM
  4. Returning collections?
    By clintonf in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-26-2008, 12:58 PM
  5. newbie needs help with collections
    By rozner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-02-2005, 09: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