+ Reply to Thread
Results 1 to 9 of 9

Duplicate Indicator Macro Trouble

  1. #1
    Registered User
    Join Date
    11-20-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2000/2010
    Posts
    4

    Duplicate Indicator Macro Trouble

    Hi Folks,

    Hoping you can help me. I'm sure it's something basic I'm not understanding (I'm pretty new at this so be gentle!).

    I have 3 sets of data (but let's start with just 2) that I want to compare against each other to find duplicates.

    The data is text from word/text/web files.

    After compiling this data into columns, I am attempting to either cut/paste or import the data into separate columns in the same excel sheet so that I can use the following macro to discover the duplicates in each column.

    However, for some reason, although I know that there are duplicates in the data, the macro isn't finding them.

    I've discovered that if I cut/paste a cell from one column to the next (overwriting the duplicate data) it will find them.
    I've discovered that if I were to type the data manually, it will find the duplicates.

    SO, it seems that there's an issue with the data being copied/pasted or the way I am importing it.
    I've tried saving the MS Word documents as .txt files so that I can import them.
    I've tried ensuring that the formatting of the text is exact, including font, size, capitalization etc.

    Any help would be much appreciated.

    Private Sub CommandButton1_Click()
    Dim CompareRange As Variant, To_Be_Compared As Variant, x As Variant, y As Variant
    str1 = InputBox("Enter Column Name to be Compared")
    str2 = InputBox("Enter Column Name to Compare")
    str3 = InputBox("Enter Column Name to put the Result")
    Range(str1 & "1").Select
    Selection.End(xlDown).Select
    Set To_Be_Compared = Range(str1 & "1:" & Selection.Address)
    Range(str2 & "1").Select
    Selection.End(xlDown).Select
    Set CompareRange = Range(str2 & "1:" & Selection.Address)
    I = 1
    To_Be_Compared.Select
    For Each x In Selection
    For Each y In CompareRange
    If x = y Then
    Range(str3 & I).Value = x
    I = I + 1
    End If
    Next y
    Next x
    End Sub

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Duplicate Indicator Macro Trouble

    Maybe try this:

    Please Login or Register  to view this content.
    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  3. #3
    Registered User
    Join Date
    11-20-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2000/2010
    Posts
    4

    Re: Duplicate Indicator Macro Trouble

    Thanks aboutsetta!

    Unfortunately your macro didn't show any results either, but I will keep it on file for future use.
    When I compare the lists to themselves, these macros work to find duplicates, however when compared to different lists, they find nothing?

    I'm wondering if it's a problem with the way my data is formatted.

    Is there a particular way one should format the data for best results? (font, size, should they be the same?)
    Does it have to be in alphabetical order?
    Is it better to cut/paste your data or import it via text file? Or does it have to be manually typed in order for the macros to work?


    I'm extremely confused why these 2 macros that really do work wont work on the lists I'm trying to compare...

    Any ideas are appreciated.

    Thanks

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Duplicate Indicator Macro Trouble

    Hi,

    Can you upload a sample of data? If it sensitive then you can use dummy data.

    abousetta

  5. #5
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Duplicate Indicator Macro Trouble

    Here is an example showing that it works with simple data. Font, size, etc. do not matter. I have updated the code to convert everything first to text and capitalize that should take care of issues of numbers stored as text and capital vs. small case.

    abousetta

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by abousetta; 11-21-2012 at 01:44 PM.

  6. #6
    Registered User
    Join Date
    11-20-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2000/2010
    Posts
    4

    Re: Duplicate Indicator Macro Trouble

    Thanks aboutsetta.

    Here are the 2 files. I happen to know that there is duplicate data - Complete Wellhead & Valve Servicing Ltd. - is one of them.

    Thanks so much for your help!
    Attached Files Attached Files

  7. #7
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Duplicate Indicator Macro Trouble

    Changed the code above. It now gives you the result you are looking for.

    Now it's important for you to understand the problem. The two duplicates don't match 100%. They code now looks for a match between what is in column A, and part of column B. In other words A must be part of B and therefore B must be the same as A or have a larger length.

    So when running the code, the first imported file must be the one with the shorter name and the file with the longer file must be the one with the longer name (or additional address). This of course does not handle spelling mistakes, reordered words, etc. If that is required then you will need to use fuzzy logic.

    abousetta

  8. #8
    Registered User
    Join Date
    11-20-2012
    Location
    Edmonton, Canada
    MS-Off Ver
    Excel 2000/2010
    Posts
    4

    Re: Duplicate Indicator Macro Trouble

    Thanks aboutsetta, this will save me days of searching and testing. Worked exactly as I needed it to.

    You are awesome!

  9. #9
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Duplicate Indicator Macro Trouble

    No problem. Glad I could help.

    A question for you that might save you some more time. How are you getting this information into Excel and do you actually need it in Excel? There are many ways to streamline things if you want. Just let us know.

    abousetta

    P.S. Thanks for marking the thread as solved.

+ 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