+ Reply to Thread
Results 1 to 11 of 11

How to find a duplicate value from two cell values

  1. #1
    Registered User
    Join Date
    07-29-2019
    Location
    Detroit, USA
    MS-Off Ver
    Office 365
    Posts
    4

    How to find a duplicate value from two cell values

    Hi All,

    I have column A with values as initial value and column B with final value, say 1000 in a cell of column A and Value and 1999 in a cell of corresponding row of column B that mean both columns make a range of numbers containing values 1000 till 1999 for that row. I need to find the duplicates for any any occurrences. For example if there is another row with range of 1900 till 2500, this means that there are duplicate numbers from 1900 till 1999. Business provide us list of accounts with ranges listed in Column A and B that we upload in Database. We cannot have duplicate account numbers and need to identify those before uploading in database. Looking to create a VBA script that could identify these duplicate. I would appreciate your help. Thank you.

    Column A Column B
    1000 1999
    1900 2500

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to find a duplicate value from two cell values

    Please upload a workbook or a representative cut down copy, anonymised if necessary. It is always easier to advise if we can see your request in its context.

    Show a before and after situation with manually calculated results, explaining which information is data and which is results, and if it's not blindingly obvious how you have arrived at your results some explanatory notes as well.

    To upload a file click the Go Advanced button at the foot of your post, look underneath the post area for the Manage Attachments section and take it from there.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2016
    Posts
    949

    Re: How to find a duplicate value from two cell values

    hi, try

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    07-29-2019
    Location
    Detroit, USA
    MS-Off Ver
    Office 365
    Posts
    4

    Re: How to find a duplicate value from two cell values

    Thank you, k1dr0ck,

    Above solution only works for the values listed in Column A and B but ignores what falls in between those numbers. Let me explain one more time with example and data.

    Here is the set of columns

    Column A Column B
    3300600000 3300600999
    3300601000 3300601049
    3300601050 3300601999
    3300602000 3300602019
    3300602020 3300604999
    3300605000 3300605999
    3300606000 3300612999
    3300613000 3300613999
    3300614000 3300614999
    3300615000 3300615999
    3300620000 3300620999
    3400644000 3400644199
    3400651000 3400654499
    3400654000 3400666199
    3400666000 3400666199

    Now if we see last three rows have duplicate account numbers, third last row have accounts from 3400651000 up til 3400654499 so accounts in this row from 3400654000 to 3400654499 are also included in the accounts listed in second last row from 3400654000 till 3400666199. same is the case with second last row and the last, there are accounts that are included in both rows.
    Hope I tried to make you understand.
    Please feel free if you have any question.

  5. #5
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2016
    Posts
    949

    Re: How to find a duplicate value from two cell values

    if I understand correctly retrieve the duplicate values that intersect between column A and B?

    try the attach file i used your data on post #4

    the macro takes a while to generate the result
    the duplicate values are shown in column D

    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: How to find a duplicate value from two cell values

    You may also try something like this...

    Please Login or Register  to view this content.
    Please click the button called "Find Duplicates" on Sheet1 to run the code.
    Attached Files Attached Files
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  7. #7
    Registered User
    Join Date
    07-29-2019
    Location
    Detroit, USA
    MS-Off Ver
    Office 365
    Posts
    4

    Re: How to find a duplicate value from two cell values

    Thank you, so much k1dr0ck and sktneer.
    Both worked. But I changed k1dr0ck script so can highlight row that is getting duplicated. But I am now getting overflow as this file is pretty big.
    Issue comes in the loop - cstartA = CLng(Sheet2.Range("D" & x).Value)

    I am attaching the whole file. your help would truly be appreciated.
    Thank you for support.

    Here is the VBA code I am using, and underlined bold where I get overflow error after running for a while. It probably process almost 2/3 of file as I see Reds in the row uptil that before its error out.

    Sub find_intersect()
    Dim startA As Long, stopB As Long, cstartA As Long, cstopB As Long, lastrw As Long, x As Long, i As Long, y As Long, svalue As Long, cvalue As Long, rowD As Long


    lastrw = Sheet2.Range("A" & Rows.Count).End(xlUp).Row
    For i = 2 To lastrw
    startA = Sheet2.Range("A" & i).Value
    stopB = Sheet2.Range("B" & i).Value
    x = i + 1
    For y = x To lastrw
    cstartA = CLng(Sheet2.Range("A" & x).Value)
    cstopB = CLng(Sheet2.Range("B" & x).Value)
    If Sheet2.Range("A" & x).Row > lastrw Then
    Exit Sub
    Else
    For svalue = startA To stopB
    For cvalue = cstartA To cstopB
    If cvalue = svalue Then
    rowD = rowD + 1

    Range("A" & i & ":B" & i).Interior.Color = vbRed

    End If
    Next cvalue
    Next svalue
    End If
    Next y
    Next i

    End Sub
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor
    Join Date
    12-01-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2016
    Posts
    949

    Re: How to find a duplicate value from two cell values

    you should use sktneer's code it's much faster
    maybe you can ask him to add a code to highlight the rows which has duplicates

    found out my code display's the duplicate values several times in D
    maybe that's why it takes too long, i have yet to figure out why

    also it has an overflow error because
    Long data type can hold integer values between -2,147,483,648 and 2,147,483,647
    Last edited by k1dr0ck; 08-01-2019 at 04:41 AM.

  9. #9
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: How to find a duplicate value from two cell values

    You may give this a try and see how this works for you...

    Please Login or Register  to view this content.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    07-29-2019
    Location
    Detroit, USA
    MS-Off Ver
    Office 365
    Posts
    4

    Re: How to find a duplicate value from two cell values

    Thank you, so much k1dr0ck and sktneer.
    I used sktneer script and it worked perfect, also very efficient.

    Regards

  11. #11
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: How to find a duplicate value from two cell values

    You're welcome!

    If that takes care of your original question, please mark your thread as Solved by selecting Thread Tools (just above your first post) --> Mark 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)

Similar Threads

  1. Replies: 1
    Last Post: 10-12-2018, 12:19 PM
  2. Need to find duplicate cell values from ONLY cells containing a specific character
    By m_roussakis in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-04-2018, 06:00 AM
  3. [SOLVED] Macro to find duplicate values in different workshhet and change cell colour.
    By Gaztr1x in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-26-2015, 04:12 PM
  4. [SOLVED] Find count of Unique or Duplicate Values based on Concatenated values in 2 columns
    By bdicarlo1 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 12-03-2014, 12:42 AM
  5. [SOLVED] Find duplicate values and then copy adjasent vale to empty cell
    By dettrix in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-05-2012, 09:26 AM
  6. How can I find duplicate values in a column and then change the value of a cell?
    By Excelcod in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-06-2011, 02:59 PM
  7. Find right cell (with duplicate values)
    By leonidas in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-04-2006, 11:19 AM

Tags for this Thread

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