+ Reply to Thread
Results 1 to 9 of 9

Match two Arrays from different worksheets

  1. #1
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Match two Arrays from different worksheets

    hello,

    I want to create a macro that matches each record from a worksheet I call "ATemplate" with another worksheet I call "BTemplate" using an unique ID (the ID row title is called "AT2RecID") that exists in both worksheets. For the sake of simplicity I only used several records as opposed to the thousands that I have in both worksheets. The workbook I provide with this post includes the following worksheets:

    - ATemplate
    - BTemplate
    - Output Results

    What I want the Macro to create in a new worksheet is the example found under worksheet "Output Results". In worksheet "Output Results" row titles should start IN ROW 2 and the data should start IN ROW 3. Row Titles B THROUGH M along with its associated data from worksheet "ATemplate" come over to the "Output Results" worksheet and Row Titles O and P along with its associated data from worksheet "BTemplate" come over to the "Output Results" worksheet. Again the records are matched up by the row title "AT2RecID" found in both worksheets "ATemplate" and "BTemplate". I understand I can do this in Access, but I would really like to see how it works in VBA.

    thanks much!
    Attached Files Attached Files
    Last edited by boldcode; 03-25-2013 at 01:49 PM. Reason: Solved

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

    Re: Match two Arrays from different worksheets

    Try this code

    Please Login or Register  to view this content.
    Last edited by AB33; 03-23-2013 at 04:22 PM.

  3. #3
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Match two Arrays from different worksheets

    AB33,

    The code seem to work just fine; is there some code that will create a new worksheet "Output Results" and put the results there as oppose to me creating "Output Results" manually in order for the code to work.

    Thank you for your help AB33.

    - BC

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

    Re: Match two Arrays from different worksheets

    Please see above amended code.
    Last edited by AB33; 03-23-2013 at 04:25 PM.

  5. #5
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Match two Arrays from different worksheets

    Another way

    Please Login or Register  to view this content.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  6. #6
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Match two Arrays from different worksheets

    mike7952,

    I will test out your code and let you know where I stand. Thanks for the help.

    - BC

  7. #7
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Match two Arrays from different worksheets

    Mike7952,

    Is there any way to change your code so that results are displayed in the Active Worksheet as opposed to a predifined one.

    Thanks,

    Bc

  8. #8
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Match two Arrays from different worksheets

    mike7952,

    I figured out how to use the ActiveSheet so no worries there. Question about your variables, how come variables aArr, w, and aOutput() are not defined as anything. I would like to define them so they are not Variant or defaulted to Variant.

    - BC

  9. #9
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Match two Arrays from different worksheets

    BC,

    They need to be variant.

  10. #10
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Match two Arrays from different worksheets

    Mike,

    I figured out with the those variant variables mean, but I can't figure out what the "n" variable variant does. I was wondering if you could shed some insight on that particular variable.

    - BC

  11. #11
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Re: Match two Arrays from different worksheets

    Mike,

    I figured it out. Thank you for your solution!

    - Bc

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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