+ Reply to Thread
Results 1 to 8 of 8

Generating 'Key' via VBA Macro

  1. #1
    Registered User
    Join Date
    03-03-2017
    Location
    Ontario, Canada
    MS-Off Ver
    2016
    Posts
    2

    Generating 'Key' via VBA Macro

    Hello everyone,

    I've a large data set, 17,000 rows, many columns etc.
    I basically need to compare combinations of data between two columns. My idea was to create a 'key' column that basically combined the data together making it easier to compare and see where variations may be. The only problem, at least for my skill level, is that the data i needed to combine was split between multiple rows - not columns. I've been searching how to do this and read this can be done via an array formula; however, I know this can soak up a lot of resources on large data sets and I read that may not be the ideal solution - that a VBA solution may be best.

    An example of the data I may have is below with an example of what I'm trying to achieve on the rightmost column. Teh result can be displayed in an adjacent column, worksheet, etc. - whatever is easiest.

    Does anyone have any ideas/thoughts?

    Column1 Column2 Desired Result
    1.1.1 A 1.1.1,A,B,C
    1.1.1 B 1.1.1,A,B,C
    1.1.1 C 1.1.1,A,B,C
    1.1.2 D 1.1.2,D,E,F,G
    1.1.2 E 1.1.2,D,E,F,G
    1.1.2 F 1.1.2,D,E,F,G
    1.1.2 G 1.1.2,D,E,F,G
    2.1.1 H 2.1.1,H,I
    2.1.1 I 2.1.1,H,I

    Thanks in advance!

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Generating 'Key' via VBA Macro

    Hi Mrom,

    Give this a shot:

    Please Login or Register  to view this content.
    P.S. Welcome to the forum.
    Last edited by Arkadi; 03-03-2017 at 10:42 AM.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Generating 'Key' via VBA Macro

    Are the A B C D E F G (in the middle) the last character of column1 or the 1st character of column2?
    Does everything fit this X.X.X pattern or are some values XX.XX.XX?
    thanks
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: Generating 'Key' via VBA Macro

    When I look at your data, I'd say: You already have a key in column 1 :-)

    Anyway, let's try another approach - just with arrays (I assumed your data is sorted on column 1):
    Please Login or Register  to view this content.
    Best Regards,

    Kaper

  5. #5
    Registered User
    Join Date
    03-03-2017
    Location
    Ontario, Canada
    MS-Off Ver
    2016
    Posts
    2

    Re: Generating 'Key' via VBA Macro

    Wow, you guys are fast! - Thanks so much!

    Arkadi,
    Your code worked beautifully on the sample I had! I modified the columns to match the main document and after freezing for awhile it actually did EXACTLY what I was hoping... Thanks SO much! Much appreciated.

    Kev_,
    Sorry about the clarity of my initial post. It looked nice when I was typing it in but got distorted when submitting. I'll make sure to post an excel file next time.
    The letters in the same were part of column2
    The values can vary in format unfortunately.

    Kaper,
    In reality I work in architecture and I'm dealing with an equipment list. Column 1 would be a number designated to a room and column2 an id code for the equipment belonging to that room. I'm basically trying to combine the number combinations with the equipment combinations to determine similar conditions to apply 'templates' to those rooms.

    I just got Arkadi's code to work, I'll actually try out yours as well as I'm always excited to see multiple ways of doing the same thing!

    Thanks again so much everyone for your help! It's greatly appreciated!

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Generating 'Key' via VBA Macro

    Happy to help MRom1! Thanks for the feedback, the rep, and marking the thread as solved

  7. #7
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,623

    Re: Generating 'Key' via VBA Macro

    Glad it worked for you. And thanks for reputation point and for marking therad as SOLVED
    Happy exceling :-)

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Generating 'Key' via VBA Macro

    Arkadi's code has the advantage that data don't need to be sorted. However code runs slower because of too much sheet interaction during execution.

    Kaper's code runs much faster but has the disadvantage that data needs to be sorted.

    So I made you a code that has the best of both worlds. Try it out just for fun.

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

+ 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. Glossary Generating Macro
    By dexterousy in forum Word Programming / VBA / Macros
    Replies: 23
    Last Post: 11-13-2014, 11:54 PM
  2. [SOLVED] Generating all possible combinations per macro
    By KaNi2015 in forum Excel Programming / VBA / Macros
    Replies: 27
    Last Post: 10-06-2014, 10:36 AM
  3. Generating mail messages with a Macro
    By Jarkova in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-30-2013, 03:05 PM
  4. Generating reports using macro
    By cvsuryam in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-02-2011, 03:09 PM
  5. Combination generating macro needed
    By smiso24 in forum Excel General
    Replies: 1
    Last Post: 04-12-2010, 03:27 PM
  6. macro generating chart from square..
    By srdreddy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-27-2008, 03:25 PM
  7. VBA code generating from macro
    By ethcbi in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2007, 05:12 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