+ Reply to Thread
Results 1 to 8 of 8

Changing validation list

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Changing validation list

    I am beginning to really hate drop down in cell data validation boxes! Apart from the fact they don't trigger a WorksheetChange event I've now a problem I really don't get.

    The sheet is protected, the cell with the drop down is not. Based on another sheet the idea is that when the user ends up on this sheet the range of dropdown options changes based on prior answers. The code itself is dead straightforward. I've stripped it back to a simple line. OK two lines for this purpose.

    Range("d3").Select
    Selection.Validation.Modify Formula1:="=$F$3:$F$4"
    Runs nicely on unprotected sheet. Not on protected sheet. Even one where only the user interface is locked. Am I doing something wrong here or is this yet another drawback of these damn things? If so, other than having the code unlock and relock, is there a workaround?

    Many thanks

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,207

    Re: Changing validation list

    Selecting a value in a cell with a Data Validation dropdown absolutely does trigger a Worksheet_Change. Ensure that you have Application.EnableEvents = True.

    However, I was able to reproduce your other problem. I was surprised but the standard way to work around this is to Unprotect before and Protect after. Also don't bother to Select.

       Unprotect
       Range("D3").Validation.Modify Formula1:="=$F$3:$F$4"
       Protect
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: Changing validation list

    It was clumsy coding to illustrate a point but yes no selection is being made (some days I'm just too lazy!)

    I've never had it work re WorksheetChange, but I'll have a look and make sure none of the code is left with the events off. Thanks.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,207

    Re: Changing validation list

    I set this up as a test based on your description, if it would be of any help.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: Changing validation list

    ALso didn't know about the way you gave the cell references there. That'll save some time!

  6. #6
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: Changing validation list

    OK I take part of that back - suddenly I use target.column and all is golden. I'll need to go back and see what I did wrong before!

  7. #7
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: Changing validation list

    Hmmmm so it clearly works - I need to revisit some code! Thanks.

    Also solved my own problem. I was getting too cute frankly. All I actually needed to do was leave the list and validation as was, but use a formula to change the contents of the list that fall into the validation. Simple really. Sometimes knowing to much is a problem

  8. #8
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: Changing validation list

    Hoping you are subscribed to this. I tried something out this morning. The Worksheet_Change code you gave me clearly worked. HOwever I ran into a problem (which is likely why it didn't work for me at all). Now it may not be an issue but normally I set up my change events to only run when a specific column is changed - the column that has the dropdown validation boxes in it. If I do that the change event won't trigger. Try adding the selection to your code and see if it still works. Either I'm getting something wrong or it just plain doesnt. Either way I'd be interested to know. Thank.

+ 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. Changing Two Validation List Entries Simultaneously
    By AliGW in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-23-2015, 07:22 PM
  2. changing font on data validation list
    By superchew in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-28-2014, 01:31 PM
  3. Changing colour on changing a Data Validation List added with VBA
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-16-2011, 08:15 AM
  4. Replies: 4
    Last Post: 05-17-2011, 06:07 PM
  5. Changing value of Data validation list when another cell changes
    By chamdan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-01-2011, 02:38 PM
  6. Changing Font etc in a Validation list
    By Not A Clue in forum Excel General
    Replies: 1
    Last Post: 11-12-2006, 06:11 PM
  7. Changing named Validation list to Dynamic list.
    By GlenC in forum Excel General
    Replies: 1
    Last Post: 07-20-2006, 06:55 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