+ Reply to Thread
Results 1 to 2 of 2

Userform listbox - macro to prevent duplicates being entered to worksheet from listbox

  1. #1
    Registered User
    Join Date
    01-05-2020
    Location
    Australia
    MS-Off Ver
    10
    Posts
    1

    Userform listbox - macro to prevent duplicates being entered to worksheet from listbox

    I have 2 listboxes in a userform. The idea is that the user can select items in listbox1 and move them to listbox2. Once they click “commandbutton4”, the data from listbox2 is pasted into my worksheet in column E.
    I would like to be able to avoid duplicate entries from listbox2 to the worksheet. I built the below code but it does not quite do what I want.

    I would like the code to do this – if there is say 4 entries in listbox2, and 2 entries are already in the spreadsheet (duplicates) and 2 are original, I would the a message box to pop up & identify which of the entries in listbox2 are duplicates. It would also be good if the duplicates could be highlighted so its easier for the user to remove from the list. Once the duplicates are removed, the user clicks on “commandbutton4” again and the entries are transferred to the worksheet.

    My current code does half the job - if there is 2 original entries followed by 2 duplicates in the listbox2, it notifies the user about the duplicate. However once the duplicate is removed, as the original entry is at the top of the list, when pressing the “commandbutton4”, it says the original is also a duplicate, and once I exit the userform it appears on my spreadsheet. Obviously I don’t want the code to identify a “duplicate” that is not yet on the worksheet.

    Any help would be greatly appreciated

    PS - I have taught myself VBA for all of 2 weeks - this code may be absolutely terrible

    Please Login or Register  to view this content.

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,295

    Re: Userform listbox - macro to prevent duplicates being entered to worksheet from listbox

    Welcome to the forum, problems are easier to solve when we can see the whole context

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

+ 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. [SOLVED] Allow users to edit or add to previously entered Listbox selections in UserForm
    By lorikgator in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-23-2015, 05:01 PM
  2. [SOLVED] if anything in listbox select first item, if listbox empty do nothing (listbox in userform
    By mcdermott2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-17-2015, 12:49 PM
  3. Multicolumn dynamic Listbox - Remove Duplicates in Listbox
    By s2jrchoi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-13-2014, 12:30 PM
  4. userform listbox
    By tsiguy96 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-14-2013, 11:09 PM
  5. Listbox to Listbox, no duplicates & submitting same UserForm data for each Listbox entry.
    By jamieswift1977 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-18-2012, 12:18 PM
  6. VBA userform listbox populate data entered from comboboxes
    By Hilton1982 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-05-2012, 11:29 PM
  7. [SOLVED] avoiding duplicates in listbox (added from another listbox)
    By KR in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-14-2006, 04:15 PM

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