+ Reply to Thread
Results 1 to 7 of 7

Remove All Instances Of Key Item Pairs From Dictionary

  1. #1
    Forum Contributor
    Join Date
    01-07-2004
    Posts
    314

    Remove All Instances Of Key Item Pairs From Dictionary

    Hi all,

    Using excel 2010.

    I definitely have duplicate values in keys and unique values in items in a dictionary
    I tried to loop through a control array and i fthe key exists in the dictionary remove it.
    Not working correctly, 8 items are removed from the dictionary, but the array has 10 items in it

    thx
    w

    Please Login or Register  to view this content.
    Kind regards,
    w

    http://dataprose.org

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Do you mean you are trying to create a dictionary of unique items but you are ending up with duplicates?
    If posting code please use code tags, see here.

  3. #3
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Remove All Instances Of Key Item Pairs From Dictionary

    Not sure why you're having this problem

    Please Login or Register  to view this content.
    For testing purposes, put something repeated in Range("A1:A6") and run this:

    Please Login or Register  to view this content.
    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Remove All Instances Of Key Item Pairs From Dictionary

    You may have 10 items but 8 keys, which means you have two duplicate items and can have a single key.
    Or when you assign the range in to the variant aControl, you are missing two rows. As the code loops through the array, these two items are missing.

  5. #5
    Forum Contributor
    Join Date
    01-07-2004
    Posts
    314

    Re: Remove All Instances Of Key Item Pairs From Dictionary

    Thanks everyone,

    I'm still a little stumped trying to compare values in the dictionary to a control array and it could partly be just because I expect different output
    For example, the first element of the control array is 41.
    I think should search the dictionary, if found, write result to immediate window
    Found : 41 6
    But you can see below, it is listed 5th in the sequence

    Additionally, there are a couple of items listed as Found, but are not in the Control array, but they are in the dictionary

    It seems that the .Exists Method of the Dictionary Object is looking at the item and not the key?
    If my assumption is correct, is it possible to look at the key to determine if it exists?

    The workbook is attached

    thx
    w

    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Remove All Instances Of Key Item Pairs From Dictionary

    Here's a simplified approach that works for me:

    Please Login or Register  to view this content.
    Notice I don't check if the key exists or not. If you try to add it, it will only add it to the keys if it is not already present.

    abousetta

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,554

    Re: Remove All Instances Of Key Item Pairs From Dictionary

    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. Replies: 5
    Last Post: 05-17-2012, 10:51 PM
  2. 2 Dimentional Array as Dictionary Item
    By erock24 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-05-2011, 11:13 AM
  3. Remove Duplicate Pairs(2 Columns)
    By deathswan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-31-2006, 08:25 PM
  4. Dictionary object: Error assigning user defined data type to item
    By Paul Urbanus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2005, 12:25 AM
  5. Counting Instances Of Item In A Column
    By Mr Milquetoast in forum Excel General
    Replies: 15
    Last Post: 06-04-2005, 09:05 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