+ Reply to Thread
Results 1 to 5 of 5

UDF that returns a data validation list

  1. #1
    Forum Contributor
    Join Date
    07-28-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    104

    UDF that returns a data validation list

    I have a series of drop-down lists. Most of them are populated with named ranges. However, sometimes, the criteria changes, and they need to be populated with a custom list. I have it set up currently where I have off-screen formulas. If a cell includes a semicolon, then I assume I need to build a custom range. So, the next 50 cells are devoted to turning the semicolon-delimited list into a range that can be used for the data validation. So, my data validation formulas are rather complex:

    Please Login or Register  to view this content.
    For this example, WW10 contains either the name of the range or a semicolon-delimited list of values that should be present in the range. So, XD10 is a formula to count the number of semicolons in WW10. If it is 0, then that means that it is just a range name, and INDIRECT(WW10) returns that range. But, if it is a semicolon-delimited list, then I build that list dynamically starting from XK10 to however far out I need to go to the right. I can then copy this down and the validation formula updates automatically for the hundred and fifty rows that I need this validation for. Each row has ten of these potentially dynamic lists. It is rare they will be populated by a dynamic list, so for the most part, the formulas are not needed. So, multiplying out, that is 150x10x51=76,500 cells with formulas. And at first, this was no big deal. But, over time I have had to add additional copies of this same sheet, each with similar formulas. The workbook is starting to slow down. Is there a way to replace all of this manual manipulation with a UDF that could use

    Please Login or Register  to view this content.
    If that returned a range, that would potentially solve all of my problems. I would not need 76,500 formulas per page, which I think has the potential to speed things up a bit. At this point, I would be able to remove close to a million formulas if that were the case (out of the million, maybe a thousand are actually being used for this purpose). So, is there a way to return a Range object that does not actually point to a range, but makes Excel think that it does?

    Attached is a simple example of the current functionality.

    Edit: Since a UDF referenced from a cell cannot update another range, this may not be possible.
    Attached Files Attached Files
    Last edited by SlipEternal; 06-23-2020 at 10:39 AM. Reason: Marking this solved

  2. #2
    Forum Contributor
    Join Date
    07-28-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    104

    Re: UDF that returns a data validation list

    As I research this further, it has become apparent to me that this is not possible through VBA. I appreciate anyone who looked into it for me, but I am going to mark this as Solved, as the solution is to keep the existing structure, even if it is a bit slow.

  3. #3
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: UDF that returns a data validation list

    Hi, as you say, you cannot achieve this with a UDF but you could, perhaps, get away with using the Selection Change event?

    Referencing your sample file, if you right click on Sheet1 -> View Code - paste below into resulting window.

    You should then find that as you select the DV cells the lists will reflect contents of B, and if a semi-colon delimited list you will get those contents
    (e.g. if you change B3 to include additional items, and select A3 so the DV list should update accordingly)

    Of course, there is some overhead with the Selection event - so whether or not it's worth pursuing will be up to you...

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by XLent; 06-23-2020 at 11:52 AM. Reason: added attachment for OP

  4. #4
    Forum Contributor
    Join Date
    07-28-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    104

    Re: UDF that returns a data validation list

    Quote Originally Posted by XLent View Post
    Hi, as you say, you cannot achieve this with a UDF but you could, perhaps, get away with using the Selection Change event?

    Referencing your sample file, if you right click on Sheet1 -> View Code - paste below into resulting window.

    You should then find that as you select the DV cells the lists will reflect contents of B, and if a semi-colon delimited list you will get those contents
    (e.g. if you change B3 to include additional items, and select A3 so the DV list should update accordingly)

    Of course, there is some overhead with the Selection event - so whether or not it's worth pursuing will be up to you...
    This is an excellent suggestion. I have been trying to avoid event handlers because the users sometimes go too quickly, and the VBA does not update in time, allowing the user to choose options that should be impossible. Given the variety of potential inputs, this could cause calculation issues later that could go uncaught. Still, an excellent suggestion, and this would usually be a great solution.

  5. #5
    Forum Contributor
    Join Date
    07-28-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    104

    Re: UDF that returns a data validation list

    I actually went back and redesigned the bulk of this. The benefit of custom lists that turn into data validation is that users can create their own data validation for each other. But, these custom lists are not typically needed. The existing data validation lists are typically good enough. But, for the occasion when the custom list was needed, I just created dynamic named ranges where users could enter their own list. Each such list is labeled letting the user know which named list to use for the data validation cell. So, instead of users creating custom semicolon-delimited lists, now they just add values to preexisting lists that are not tied to any data validation, then assign that list. Even if I need a thousand custom lists, it is unbelievably faster than the extra million or so formulas that I was using. The entire spreadsheet is faster and more stable. I don't know why I did not think of this sooner. It is a more obvious approach, anyway, and does not require any VBA at all.

+ 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] VBA to Prevent Data Entry in Cell with Data Validation List - Two Criteria Validation
    By AliGW in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 05-25-2019, 11:48 AM
  2. Data Validation returns duplicated results
    By Tony0731 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-31-2018, 07:03 AM
  3. Replies: 1
    Last Post: 01-14-2018, 11:04 AM
  4. Replies: 3
    Last Post: 06-04-2015, 02:27 PM
  5. [SOLVED] Formula error - data validation + HLOOKUP returns #N/A
    By ratpackinc in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-01-2014, 01:25 PM
  6. [SOLVED] Data validation only returns data from the drop down list but not when entered!
    By carlandtina02 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-23-2013, 08:04 AM
  7. Replies: 3
    Last Post: 04-11-2011, 05:52 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