+ Reply to Thread
Results 1 to 7 of 7

VBA: Pull unique text records from multiple columns and store into array?

  1. #1
    Registered User
    Join Date
    12-19-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    24

    VBA: Pull unique text records from multiple columns and store into array?

    Hi all,

    Please bear with me - I'm a typical Dr. Frankenstein when it comes to VBA; I splice and paste together snippets I scavenge across the net. Usually I eventually understand what I'm creating but I've ran into a problem here.

    What I want to accomplish: a function that pulls unique records (text) from a number of predefined columns in a range of arbitrary size and stores it in a variable for later use.

    What I've got now: a function that pulls unique records from predefined column #1 and pastes them into a cell M10 and after that pulls the unique records from predefined column #2 and pastes them over cell M10. Not that useful yet.

    It seems simple enough to just put the unique records found in predefined column #1 in a "queue" while the function fetches the unique records in column #2 and join the two, but my trial'n'error-efforts with another loop have yet amounted to nothing.

    Any help with this would be greatly appreciated so many thanks in advance!

    PS: I'm guessing that the "Scripting Dictionary" requires the user to install a Microsoft add-on, so if that's the case a work-around without that method would be desirable.
    Please Login or Register  to view this content.
    Last edited by kaptenstofil; 06-24-2014 at 05:24 AM.

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: VBA: Pull unique text records from multiple columns and store into array?

    The "Scripting Dictionary" is not an add-on, but a reference to a code module. Once you set it, the user will be unaware of it UNLESS that don't have it installed on their system.

    We can use the normal Collection object to get our unique list without setting a reference.

    Are the column headers("<Account>", "<Party account>") always in 1-2 position, or do we need to search for them?
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    12-19-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: VBA: Pull unique text records from multiple columns and store into array?

    Hi Tinbendr!

    Yes, I'd like it to search the range for "<Account>" and "<Party account>". Otherwise I'd tried to point to a cell reference instead.

    I was under the impression that the sub actually manages to do this at present? Oh wait. I should've posted the function behind If IsInArray(strVal2, AccCol)
    Please Login or Register  to view this content.
    Sorry for leaving that out above!

  4. #4
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: VBA: Pull unique text records from multiple columns and store into array?

    Hi...

    Try this..

    It will search for your 2 Column headers.. then loop through each of those column headers columns.. adding the values to the Dictionary..

    The Keys (unique values) are then found in the Z array.. monitor the Locals window to see it happening..

    The Msgbox is just there to show you what is in the array...

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

  5. #5
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: VBA: Pull unique text records from multiple columns and store into array?

    Oh wait. I should've posted the function
    I assumed as much. We won't need that. The collection will handle that for us.

    With this code (untested BTW since I didn't have a sample sheet to work from), you end up with an array named MyAry that has a list of all the unique items in
    those columns. You'll have to decide how to proceed next. Continue with code. Or make the array Public. Or push it to the sheet.

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    12-19-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: VBA: Pull unique text records from multiple columns and store into array?

    Thank you very much both of you guys!

    apo's seem to do the trick while I get a Run-time error '9' on this row in Tinbendr's:
    Please Login or Register  to view this content.
    Now I'll just have to backwards-engineer them and try to learn something from them.

    Thanks again!

  7. #7
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: VBA: Pull unique text records from multiple columns and store into array?

    You'll get that error if the Unique.Count = 0.

+ 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] Store Multiple Non Sequential Column References in Array and then Select these columns
    By Jimbo77 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2014, 02:12 PM
  2. Need an array formula to find unique records, but don't know how to do it
    By alchavar in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-22-2013, 02:43 PM
  3. Replies: 1
    Last Post: 06-21-2012, 10:16 AM
  4. macro to store each ine of a text file in an array
    By mithil in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-19-2010, 01:41 AM
  5. counting unique records for 2 columns.
    By MarMo in forum Excel General
    Replies: 6
    Last Post: 03-31-2010, 04:04 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