+ Reply to Thread
Results 1 to 7 of 7

Removing Data Validation (list value) causes macro to not run?

  1. #1
    Registered User
    Join Date
    05-08-2017
    Location
    Toronto
    MS-Off Ver
    2016
    Posts
    81

    Removing Data Validation (list value) causes macro to not run?

    Heya,

    I'm trying to get this macro to work with the data validation removed, but I'm not sure how to get this to work. When I comment out the parts checking for data validation, and then proceed to remove data validation (under "Allow:", going from "List" to "any value"), and then click on the cell to run the macro, nothing happens.

    This is a two-piece code, with the first part being a Worksheet_SelectionChange event, and the second part being a Worksheet_Change. The former contains the relevant parts, while the latter is just for context if it helps.

    Worksheet_SelectionChange:

    Please Login or Register  to view this content.
    Worksheet_Change
    Please Login or Register  to view this content.
    It works fine when I click on a cell (a user form shows up), so long as the cell I want to select (under column J) has the list type data validation, but removing the list type DV makes it so that nothing happens when I click on the cell. I tried commenting out the parts I thought were relevant, but no luck.

    Any guidance here would be great. Version is Excel 2016.

    Thanks!
    Last edited by noname91; 02-05-2021 at 02:52 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Removing Data Validation (list value) causes macro to not run?

    The whole purpose of the code in those two event handlers is to allow multiple selections from a DV list. If you remove the DV parts, and the DV itself, there's probably nothing left for it to do.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    05-08-2017
    Location
    Toronto
    MS-Off Ver
    2016
    Posts
    81

    Re: Removing Data Validation (list value) causes macro to not run?

    Thanks for the reply TMS.

    What I basically wanted to remove the DV for was to avoid allowing duplicate selections being entered into the cell. So if the drop-down has red, yellow, green and blue, add whichever item is picked (only one unique selection is allowed at a time). But if the cell already contains, say "red, yellow, blue, red" and if you pick red, then the drop-down should cancel.

    I tried using INSTR to check for this with the oldVal and newVal variables, and while the check works if an item that already exists in the cell is picked from the drop-down list, I don't know what should be done to cancel the drop-down and break out of the program. If I try to use Exit Sub once the check is verified (INSTR(oldVal, newval) > 0), it just creates a situation where only one item is always added to the cell. The desired result is to have all the strings, but without any duplicates.

    Any ideas on how this can be done?

    Thanks again

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Removing Data Validation (list value) causes macro to not run?

    Post a sample workbook WITH the DV in place. Should be doable. But not right now; late here and no laptop in front of me.

  5. #5
    Registered User
    Join Date
    05-08-2017
    Location
    Toronto
    MS-Off Ver
    2016
    Posts
    81

    Re: Removing Data Validation (list value) causes macro to not run?

    Appreciate your looking into it!

    I've attached the workbook.

    1. "Main" sheet has the column of interest - "J". "K" is just a column that tracks the number of list entries in the row, which I included for reference.
    2. DV is intact
    3. "Backend" sheet has the list of colors.
    4. If you click on a cell under column J, inside the table, you will get a userform which will allow you to pick colors from the list. You can cancel and use the drop-down to pick the colors.
    5. Duplicate entries are detected, but if the cell is blank, it'll detect them in that case as well.
    Attached Files Attached Files

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Removing Data Validation (list value) causes macro to not run?

    Try this, courtesy of Contextures (Debra Dalgleish)

    https://www.contextures.com/excel-da....html#Multiple
    https://www.contextures.com/DataValMultiSelect.zip

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    05-08-2017
    Location
    Toronto
    MS-Off Ver
    2016
    Posts
    81

    Re: Removing Data Validation (list value) causes macro to not run?

    ^ Thanks TMS for posting that code!

    Works great, and I get to keep the DV

+ 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. Removing Spaces From Column For Data Validation Drop List
    By polodon242 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-12-2018, 09:42 AM
  2. Data validation list sorting - removing blanks
    By M1234 in forum Excel General
    Replies: 7
    Last Post: 06-27-2016, 11:15 AM
  3. Replies: 1
    Last Post: 04-25-2014, 07:44 PM
  4. Data validation List: A macro to initiate drop down list?
    By dchubbock in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-11-2013, 08:12 PM
  5. Replies: 2
    Last Post: 04-29-2013, 05:18 PM
  6. Removing multiple invalid characters for dependent data validation list
    By cuclay in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-15-2009, 01:34 AM
  7. Removing Duplicates from validation list
    By matpj in forum Excel General
    Replies: 1
    Last Post: 05-05-2009, 12:46 PM

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