+ Reply to Thread
Results 1 to 11 of 11

Populate array from unique values

  1. #1
    Registered User
    Join Date
    03-13-2023
    Location
    Luxembourg
    MS-Off Ver
    365
    Posts
    25

    Populate array from unique values

    Hi everyone

    I have a table with thousands of rows with information in several columns. I need to create an array in VBA that hosts on the first column the unique values in the "Group" column, the corresponding values from the "Group Description" column and the number of times that the Group value is repeated in that table. I want the array to be hosted in VBA but I do not want to print it in any cell in my sheet.

    Can someone please help me with the code? I attached an excel file as reference. The cells in red show the desired outcome but it's just for reference, I do not want to print it in the sheet.

    Thank you!
    Attached Files Attached Files

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,508

    Re: Populate array from unique values

    Try

    Please Login or Register  to view this content.
    PHP Code: 
    001A          ELEMENT ZONE 1               5 
    004A          ZONE 5         4 
    004B          PROJECT TRACKS               4 
    005A          STREET         2 
    005B          VENUE          19 
    005C          
    FINAL PART     1 
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,508

    Re: Populate array from unique values

    Is this resolved now?

  4. #4
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: Populate array from unique values

    Here a dictionary approach. To show how to get the data from the dictionary, the output is written to the sheet.

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: Populate array from unique values

    For writing to a sheet you just need one click in power query

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: Populate array from unique values

    In the days before Power Query, there already were query tables which you could generate like this in VBA (Just for fun to show the different methods)

    Please Login or Register  to view this content.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,508

    Re: Populate array from unique values

    In post #2, it only takes one line of code to create the array, two if you include defining the array. The rest is just to demonstrate that the array has been created as required.

  8. #8
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: Populate array from unique values

    The thing with converting Excel formula's to VBA is that you are not able to evaluate properly.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,508

    Re: Populate array from unique values

    In this example, I evaluate the worksheet formula exactly, and it produces the expected result. Not sure how the OP would use a dictionary.

  10. #10
    Forum Expert
    Join Date
    10-11-2021
    Location
    Netherlands
    MS-Off Ver
    365
    Posts
    1,386

    Re: Populate array from unique values

    With evaluating I mean stepping through code, which you can’t with formula’s in vba

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,508

    Re: Populate array from unique values

    Thanks for the rep.

+ 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] Non-array Formula to populate fields if value(s) exist in a range of unique IDs
    By bjnockle in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 02-08-2020, 11:30 AM
  2. [SOLVED] Populate a unique list from two columns- array formulas to slow!
    By strud in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2013, 11:44 AM
  3. [SOLVED] Populate an array with unique random numbers
    By Kingali in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-18-2013, 12:46 PM
  4. Replies: 2
    Last Post: 02-13-2013, 03:14 PM
  5. [SOLVED] Function to populate a list of unique values
    By Sophie.Durrant in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-08-2013, 10:57 AM
  6. Populate combo box with unique values only
    By sjayar in forum Excel General
    Replies: 1
    Last Post: 11-07-2005, 03:35 AM
  7. how to populate a combobox with a list of unique values?
    By RIOSGER in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-09-2005, 12: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