+ Reply to Thread
Results 1 to 11 of 11

VBA to check new entry for duplicates and then copy present values

  1. #1
    Registered User
    Join Date
    02-06-2016
    Location
    Denmark
    MS-Off Ver
    2010
    Posts
    28

    VBA to check new entry for duplicates and then copy present values

    Hi all.

    I know that similar problems can be found around the web, but I am new to the whole VBA thing and thus thought it better to ask.

    I have a range in a worksheet, A2:A10000, which contains reference numbers (let's called them X). What I need is that when a reference X gets entered into any cell of that range (A2:A10000), a macro will check if that reference X is anywhere else in that range, aka look for duplicates. IF there is a duplicate, I need an option popup box that asks to copy values from that duplicate (Yes or No). If selected Yes, I would like values from columns B and C, but the same row as the duplicate, to be copied to the new entry made.

    As an example, let's say that a duplicate is entered in A30 that is also found in A27. What I then need is to copy the value from B27 to B30 and the value from C27 to C30.
    I'm fairly sure this can be simply coded, but I haven't found a way to work around the row-column indexing nor the popup box.
    Last edited by Fno; 02-09-2016 at 12:32 PM. Reason: solved

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

    Re: VBA to check new entry for duplicates and then copy present values

    Can there be more than one duplicate? To use your example, a duplicate is entered in A30 that is also found in A27 and another in A20 and in A15.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    02-06-2016
    Location
    Denmark
    MS-Off Ver
    2010
    Posts
    28

    Re: VBA to check new entry for duplicates and then copy present values

    More than one duplicate may be found, yes. It does not matter what duplicate is found. Each duplicate just need the same information in columns A, B and C, while the latter columns are to be manually manipulated.
    It is a way of reducing error inputs with large data amounts.

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

    Re: VBA to check new entry for duplicates and then copy present values

    Copy and paste this macro into the worksheet code module. Do the following: right click the tab for your sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Enter your reference numbers and exit the cell.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-06-2016
    Location
    Denmark
    MS-Off Ver
    2010
    Posts
    28

    Re: VBA to check new entry for duplicates and then copy present values

    Works like a charm! Thank you!

    I have only one thing that I'm slightly curious about. If I delete the new entry I made, nothing special happens, but if I delete entries in columns A-C (the ones copied), it gives run-time error 13 Type Mismatch.
    This also happens if I do it to any other row that has not been copied to.

    It's not something big, but I'm curious if that can be solved?

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

    Re: VBA to check new entry for duplicates and then copy present values

    It looks like you are selecting A-C and then deleting it. Try this version of the macro. If you delete any reference number in column A, the corresponding data in B and C will be deleted. Does this work for you?
    Please Login or Register  to view this content.
    If not try:
    Please Login or Register  to view this content.
    Last edited by Mumps1; 02-09-2016 at 12:21 PM.

  7. #7
    Registered User
    Join Date
    02-06-2016
    Location
    Denmark
    MS-Off Ver
    2010
    Posts
    28

    Re: VBA to check new entry for duplicates and then copy present values

    Yeah, it does the trick. It still gives problems if selecting A-C and then delete is performed, but I am just guarding against the stupidity of common workers who are to use the document and have no clue about the code I am implementing.
    It does take a little while for the popup box to appear, but I guess that's to come with large ranges.

    Thank you for the help :)

  8. #8
    Registered User
    Join Date
    02-06-2016
    Location
    Denmark
    MS-Off Ver
    2010
    Posts
    28

    Re: VBA to check new entry for duplicates and then copy present values

    Oi, the last code you posted bypasses the error!
    Awesome, thank you for that!

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

    Re: VBA to check new entry for duplicates and then copy present values

    I think that you may have read my response before I revised it. This version eliminates the error message.
    Please Login or Register  to view this content.

  10. #10
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,027

    Re: VBA to check new entry for duplicates and then copy present values

    Glad it worked out.

  11. #11
    Registered User
    Join Date
    02-06-2016
    Location
    Denmark
    MS-Off Ver
    2010
    Posts
    28

    Re: VBA to check new entry for duplicates and then copy present values

    It works like a charm, really wonderful :)

    I am just trying to avoid future calls from people getting confused by the appearance of runtime errors ;)


    Thank you for the help and +REP

+ 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: 09-22-2015, 02:47 AM
  2. [SOLVED] macro to check for duplicates and copy data if no duplicate found
    By lwayl in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-22-2015, 01:31 AM
  3. Replies: 2
    Last Post: 09-03-2014, 03:37 AM
  4. Check for Duplicates when user enters values in the UserForm
    By s2jrchoi in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-27-2012, 03:43 PM
  5. Copy For Cell Values Present and not Formulas Present
    By bdb1974 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-11-2009, 12:10 PM
  6. Macro to check for blank cell entry, copy previous value, and check for duplicates
    By xPunxNotDeadx in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-26-2009, 06:33 PM
  7. check for duplicates, then sum unique values
    By Weissme in forum Excel General
    Replies: 0
    Last Post: 08-09-2006, 11:35 AM

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