+ Reply to Thread
Results 1 to 9 of 9

Cross Reference two columns and return common values?

  1. #1
    Registered User
    Join Date
    06-24-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    7

    Cross Reference two columns and return common values?

    So I've been messing around with this script for a while now.

    I have two columns organized/formatted like so:

    COLUMN A

    C180.0001
    C190.0022
    C306.2201


    COLUMN B
    C180.0001.0234
    C806.1123.1234
    C190.0022.1234
    C306.2201.4567
    C306.2201.5431



    I want this script to essentially take the Values in Column A, check them against Column B (note the xlPart in the code) then select all the values in Column B that contain anything from A. These values are then to be listed in column C


    Please Login or Register  to view this content.

    The code isn't working properly, I get an error "Subscript out of Range" on this line:

    "Set r3 = Range(Range("C2"), Range("C" & UBound(iArray())))"

    Also, when I DO get the script to work (sometimes it does) - it's not doing what I want, and it's not collecting the proper values.

    Any help is greatly appreciated

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Cross Reference two columns and return common values?

    Try:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    06-24-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Cross Reference two columns and return common values?

    Thanks for the reply!

    I see what you're doing in the script, and when I ran it sort of worked - however, I think I need to re explain what I'm trying to do.


    I have about 7000 rows of data like this, and I need to select (in column B) all the values that have the same first 8 characters (technically nine with the period, ex C100.0001) as ANY of the values in Column A. So I want to cross reference the entire column to one another.

    Is there any way to modify the script to do something like this?

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Cross Reference two columns and return common values?

    Change this line:
    Please Login or Register  to view this content.
    to this line
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-24-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Cross Reference two columns and return common values?

    I tried this, and it only works when the data in Column A is right beside (offset -1) the data in column B. I need the script to work by outputting/selecting ALL the values in Column B that have the same first 9 characters as ANY of the values in Column A.

    Would that be possible at all?

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Cross Reference two columns and return common values?

    I'm not sure what you mean. If your data is in columns A and B, then the code should work. To make it more clear, post a copy of your file with a sheet containing your source data and another sheet that shows what the data should look like after the macro is run.

  7. #7
    Registered User
    Join Date
    06-24-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Cross Reference two columns and return common values?

    here's a sample:

    SampleBook.xlsx

  8. #8
    Registered User
    Join Date
    06-24-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Cross Reference two columns and return common values?

    Fixed it. By removing the line
    Please Login or Register  to view this content.
    I managed to achieve the outcome I was looking for.

    Thank you!

  9. #9
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Cross Reference two columns and return common values?

    Glad it worked out.

+ 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