+ Reply to Thread
Results 1 to 8 of 8

Modify VBA Code to Compare Variable-Length Columns From Two Workbooks

  1. #1
    Registered User
    Join Date
    04-30-2008
    Posts
    67

    Question Modify VBA Code to Compare Variable-Length Columns From Two Workbooks

    Looking to compare two columns from two different workbooks and return matches, but it seems the code I got from the MS site assumes each column has the same number of rows, while my rows vary. How can I modify this code to allow for variable-length columns? I eventually want it to return the cell directly to the right of the workbook being compared to (Up.Load.Master_20081110.01.xls), but first things first - I need to allow for varying columns. Any suggestions?

    From the Microsoft site:

    Please Login or Register  to view this content.
    Thanks for any help
    Last edited by stusic; 11-07-2012 at 02:06 PM. Reason: Edited code to allow for fixed range, not selection. Maybe I did it right.

  2. #2
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: Modify VBA Code to Compare Variable-Length Columns From Two Workbooks

    In which column are the matching values in Up.Load.Master_20081110.01.xls file?
    Regards,
    Khaled Elshaer
    www.BIMcentre.com

    Remember To Do the Following....
    1. Thank those who have helped you by clicking the Star below their post.
    2. Mark your post SOLVED if it has been answered satisfactorily:
    • Select Thread Tools (on top of your 1st post)
    • Select Mark this thread as Solved

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Modify VBA Code to Compare Variable-Length Columns From Two Workbooks

    Its better you attach the samples, so we can test it.

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Registered User
    Join Date
    04-30-2008
    Posts
    67

    Re: Modify VBA Code to Compare Variable-Length Columns From Two Workbooks

    I'd like to upload the file, but it's got a bunch of proprietary info on it.

    The column in Up.Load.Master_20081110.01.xls is Column C, but it's in a Named Range called "Bad_Parts_Check_List_1".

    If it finds a match, I'd like to have it return the value in Column D of the same row in Up.Load.Master_20081110.01.xls.

    So, it checks the entries in Column B of the current sheet ("upload") against the named range "Bad_Parts_Check_List_1" of Up.Load.Master_20081110.01.xls. If it finds a match, it looks one cell to the right (in Column D) of Up.Load.Master_20081110.01.xls and returns that value to Column F of the current sheet (upload).

    Thanks for your help, I'll see if I can put together a sample in the meantime.

  5. #5
    Registered User
    Join Date
    04-30-2008
    Posts
    67

    Re: Modify VBA Code to Compare Variable-Length Columns From Two Workbooks

    Here's a close example. The sheets should be interpreted as different workbooks.

    The sheet for Up.Load.Master_20081110.01.xls is "Main"

    The sheet for the current workbook is "upload"

    Thanks for your help!
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    04-30-2008
    Posts
    67

    Re: Modify VBA Code to Compare Variable-Length Columns From Two Workbooks

    I found this, which seems to fit what I'm trying to do (except that I have to have the sheet open to run it), but I get an " subscript out of range" error:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    04-30-2008
    Posts
    67

    Re: Modify VBA Code to Compare Variable-Length Columns From Two Workbooks

    Any ideas? I'm soooooo close to have a working file, but just can't get this part.

    Thanks

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,719

    Re: Modify VBA Code to Compare Variable-Length Columns From Two Workbooks

    The Workbooks collection does not use the full path for the index, only the file name. That's why you get a subscript out of range. Try this.
    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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