+ Reply to Thread
Results 1 to 27 of 27

Finding duplicates in a column, prompt user then delete the current one

  1. #1
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Finding duplicates in a column, prompt user then delete the current one

    Hi there,

    I would like to have few lines to code to let Excel first find duplicates against column 1 when users enter new record. If a duplicate is found, then a pop-up window saying duplicate is found or something like that and then have Excel delete the current line so that we don't have to manually delete it by right-clicking then hit "Delete".

    The list goes on forever so I thought I should use a macro in worksheet change event, but i don' tknow how to get started.

    Is this possible?

    Please see the attached file.

    Thank you
    Attached Files Attached Files
    Last edited by Lifeseeker; 01-23-2012 at 08:24 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Finding duplicates in a column, prompt user then delete the current one

    I have this so far, which is referenced from someone else, but it deletes the entire column up to the header column. Is there any way that I just have the current row deleted as soon as it detects a duplicates?

    Please Login or Register  to view this content.

  3. #3
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Finding duplicates in a column, prompt user then delete the current one

    How about something like this?

    This just deletes the cell contents as your file is empty and I am not sure if you want the entire row deleted or entire column deleted.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by JapanDave; 01-20-2012 at 10:17 PM.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  4. #4
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Finding duplicates in a column, prompt user then delete the current one

    Hi,

    great.

    Actually, I would like the entire row to clear the contents please.

    So something like range (cells 1) to ( cells 60) . Value = ""

    possible?

  5. #5
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Finding duplicates in a column, prompt user then delete the current one

    Clear cell contents if the next value you enter in col a has a duplicate.

    Only checking column a please.

  6. #6
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Finding duplicates in a column, prompt user then delete the current one

    Quote Originally Posted by Lifeseeker View Post
    Clear cell contents if the next value you enter in col a has a duplicate.
    I had already modified the code to delete the entire row. You can have it delete from cells 1- 60 , but that will leave a blank row?

    I don't understand what you are saying in this sentence?

  7. #7
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Finding duplicates in a column, prompt user then delete the current one

    oh I see..

    hmm maybe deleting the entire row is a better option. I will check it tomorrow.

    Thank you

  8. #8
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Finding duplicates in a column, prompt user then delete the current one

    @ JapanDave,

    Your Code works Fine! I tried to tweak it to only Clear the Range found with duplicates, but it does'nt work?
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  9. #9
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Finding duplicates in a column, prompt user then delete the current one

    Hey Winon,

    Try this and see if it works for you?

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

  10. #10
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Finding duplicates in a column, prompt user then delete the current one

    @ JapanDave,

    Thank you very much for your time and effort. The code Clears the whole Row though, while I am trying to get it to clear only the range- Colums A through to Column i. This has been bugging me for a long time now.

  11. #11
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Finding duplicates in a column, prompt user then delete the current one

    I am not sure I understand.

    Eg, if you find a duplicate from what column to what column in what row do you want to clear?

  12. #12
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Finding duplicates in a column, prompt user then delete the current one

    @ DaveJapan,

    Perhaps the notes I have made in your WB attached, will clear up the misunderstanding.

    Thank you for your patience!
    Attached Files Attached Files

  13. #13
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Finding duplicates in a column, prompt user then delete the current one

    OK, how about this?

    Please Login or Register  to view this content.
    Last edited by JapanDave; 01-21-2012 at 08:37 AM.

  14. #14
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Finding duplicates in a column, prompt user then delete the current one

    Hi JapanDave,

    I think you are just great for sticking with me on this issue, thanks a lot!

    I have added to your code, as follows to clear the duplicate row from Column A to Column J:

    Please Login or Register  to view this content.

    Would there be shorter code to accomplish the same result?

    One more thing is, can your Code be changed only to fire if Duplicates are not empty.

    As it is at the moment, your code regards an empty Row, if there are two or more, as a duplicate, which in Computer terms may be correct. But the user won't understand it as such! they could just ask; "What is two or more of Nothing?"

  15. #15
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Finding duplicates in a column, prompt user then delete the current one

    Hey Winon,

    Try this and see if it is what you are after?

    Please Login or Register  to view this content.

  16. #16
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Finding duplicates in a column, prompt user then delete the current one

    @ JapanDave,

    That's it! Very kind of you. It works perfectly! I should have thought about shortening the clearing bit, myself, but for some stupid action from my side, just did not think of it! How Dumb can i get??

    You have been "Promoted" and now share a spot on my wall for people of NOTE! Congratulations! I don't award everyone with such a pretigeous honor.

    Once again, Thank you for your help.

    I have also added to your Rep.

    Keep well, and keep up the good work!!!

  17. #17
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Finding duplicates in a column, prompt user then delete the current one

    Thanks Winon, and thanks for the rep. Let me know If I can help you out further?

    Lifeseeker, if this thread is solved, please go to advance edit and mark it solved.

  18. #18
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Finding duplicates in a column, prompt user then delete the current one

    Quote Originally Posted by JapanDave View Post
    Thanks Winon, and thanks for the rep. Let me know If I can help you out further?

    Lifeseeker, if this thread is solved, please go to advance edit and mark it solved.
    Hi JapanDave,

    I will call it solved for now as I have not implemented on my system yet, but I trust that it will work out fine. Let me give it a try tomorrow!

    Thanks again

  19. #19
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Finding duplicates in a column, prompt user then delete the current one

    Hi JapanDave,

    I slightly modified the code to suit my need, but I'm stuck. Please see the attached.

    Please Login or Register  to view this content.
    In the workbook, I have two worksheets, "main" and "sub" and I'm putting the code in the "Main" worksheet.

    What I would like to do:

    You see in "sub" worksheet, there is a record 123 with diagnosis of "Neither".

    Suppose, now you are entering the record 123 in "Main" without knowing that it has been entered in the "sub.

    I would like to find a way to check or alert user that the record 123 has been entered in the "sub" already if the user is now trying to enter the same patient. then, I want excel to actually delete the 123 from the "sub", not from the "main".

    Is this doable?


    I put
    Please Login or Register  to view this content.
    so that it doesn't do this every time user moves to the next field. Is this right?

    Thank you.
    Attached Files Attached Files

  20. #20
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Finding duplicates in a column, prompt user then delete the current one

    How is the Main worksheet and sub worksheet linked? At present they are not linked.

  21. #21
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Finding duplicates in a column, prompt user then delete the current one

    Quote Originally Posted by JapanDave View Post
    How is the Main worksheet and sub worksheet linked? At present they are not linked.
    Did I have to link the two workbooks in this case?

    How do I do so?

    Thanks

  22. #22
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Finding duplicates in a column, prompt user then delete the current one

    Lifeseeker,
    OK, so you manually input data into both sheets and they are not linked. Got that.

    I don't know what you want deleted, so for the time being this macro deletes the duplicate you just entered (Tell me if you want it another way?). Enter 123 in cell A3 and see if this is what you are after?

    Please Login or Register  to view this content.
    Edit: The system is not allowing me to upload a file, paste this in the worksheet module for "Main".
    Edit* it worked. See file
    Attached Files Attached Files

  23. #23
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Finding duplicates in a column, prompt user then delete the current one

    Hi JapanDave,

    I would like the duplicate on the sub be deleted, not the main.

    So, say....if 123 already exists in sub, and when user is entering the 123 in the Main without knowing that it is already there in the sub, the system prompt user to delete the 123 from the sub, not from the main.

    Possible?
    Attached Files Attached Files

  24. #24
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Finding duplicates in a column, prompt user then delete the current one

    Try this,
    It deletes the entire row in the Sub worksheet.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  25. #25
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Finding duplicates in a column, prompt user then delete the current one

    Hey JapanDave,



    I want to give you millions of thanks. Wow, this is wonderful.

    Thank you.

    btw, I've fixed the workbook extract thing. it was the working code. But it didn't work because I had other workbooks open. Excel doesn't seem to like it when other workbooks are already open, strangely.

  26. #26
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Finding duplicates in a column, prompt user then delete the current one

    Great I could have helped.

    Dave

  27. #27
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Finding duplicates in a column, prompt user then delete the current one

    Hi JapanDave,

    Actually, due to changing priority, I would like to tie up the loose end of the other one where users are inputing record in main and it detects duplicates against the sub. (your code worked outside my system, but not inside)

    After i put your code in my system and put in a test record in main, it then started looping infinitely until i got a message saying over stack and something like outside something something failed...can't recall exactly, then the system froze.

    the code is in the worksheet_change event and whereas your code says "A" i changed it to "E" because col E is the look up column.

    Should this have happened normally?

    can you simply put the code in the worksheet_change event?

    I have made sure that i got rid of the application.enableevents pair because i'm just adding these lines into other lines.

    Any ideas?


    Sorry to bother you again!
    Attached Files Attached Files

+ 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