+ Reply to Thread
Results 1 to 12 of 12

Collection Method not adding array elements

  1. #1
    Forum Contributor
    Join Date
    06-17-2012
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    150

    Collection Method not adding array elements

    Hello VBA masters,

    I am trying to add the elements of an array to a collection to find unique elements. These will be later sent to a combobox in a userform.

    However, I am not getting any array elements added to the collection. It will be always empty after the loop.

    Here is the code
    Please Login or Register  to view this content.
    Any help will be greatly appreciated. I already spent half a day trying to find my way around this.

    Thanks.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: Collection Method not adding array elements


    Hi,

    maybe try Dictionary object, see in VBA inner help …

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Collection Method not adding array elements

    Hello icyrius,

    What does the data look like in cells H6:H? ?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Forum Contributor
    Join Date
    06-17-2012
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    150

    Re: Collection Method not adding array elements

    They are a series of four digit timestamps like this,
    1840
    1841
    1844
    1844
    1844
    1846
    1846
    1846
    1848
    1848
    1848

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Collection Method not adding array elements

    Hello icyrius,

    Let rewrite this for you so you can see how to do this correctly.

  6. #6
    Forum Contributor
    Join Date
    06-17-2012
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    150

    Re: Collection Method not adding array elements

    Perfect, Thanks!

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Collection Method not adding array elements

    Hello icyrius,

    Is the ComboBox on a UserForm or a Worksheet?

  8. #8
    Forum Contributor
    Join Date
    06-17-2012
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    150

    Re: Collection Method not adding array elements

    The code resides inside a UserForm and it is triggered with a Private Sub Userform_Activate()

  9. #9
    Forum Contributor
    Join Date
    06-17-2012
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    150

    Re: Collection Method not adding array elements

    And yes, the ComboBox is inside the Userform

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Collection Method not adding array elements

    Hello icyrius,

    This will check if there is data in Range you want to take values from. If there is no data then an alert message is displayed and the macro quits.

    This worked in my tests so it should work for you as well. Formatting your code can save you a lot time when troubleshooting code problems. Like my signature says, rushing causes delays.

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    06-17-2012
    Location
    USA
    MS-Off Ver
    Excel 2016
    Posts
    150

    Re: Collection Method not adding array elements

    YES! Thank you so much!

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Collection Method not adding array elements

    Hello icyrius,

    You're welcome.

+ 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. [SOLVED] Removing specific elements from an Array based on matching elements in a different Array
    By jamesdeuce in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-24-2014, 10:35 PM
  2. [SOLVED] How to Pass a collection to a method
    By aymanzone in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-14-2012, 06:08 AM
  3. [SOLVED] Syntax error adding additional UDT array elements
    By jdfjab in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2012, 03:19 PM
  4. Referencing Elements within an Item in a Collection
    By anthony.mcgovern in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-22-2012, 01:34 PM
  5. [SOLVED] group method - is there a collection
    By jimm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-26-2006, 01:10 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