+ Reply to Thread
Results 1 to 7 of 7

How to create a data validation list using VBA and a comma delimited list

  1. #1
    Forum Contributor
    Join Date
    09-11-2014
    Location
    Eugene, Oregon
    MS-Off Ver
    MS EXCEL 2010
    Posts
    210

    How to create a data validation list using VBA and a comma delimited list

    I want to create a data validation drop down list using VBA which would reference a single cell in Excel and in that cell is a list that goes something like BGT, FOO, HR, IT. The list is a list of unit codes that each user will have access too and the list changes based on the user access and each user could have access to nothing, 1 unit, or any number of units but I just want the data validation to always read the list in the cell that I point it to. Is this possible in VBA?

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: How to create a data validation list using VBA and a comma delimited list

    I happened to have something laying around on the bench that I could modify

    The macro CreateList does the dirty work, but you need to pass it the parameters. SheetName is the name of the sheet on which you want to place the validation. CellName is the cell address on which you want to place the validation, LookupString is the lookup string that is the source of the validation. You can either "assemble" it in code, or in the example, I put it in a named range and read that.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Forum Contributor
    Join Date
    09-11-2014
    Location
    Eugene, Oregon
    MS-Off Ver
    MS EXCEL 2010
    Posts
    210

    Re: How to create a data validation list using VBA and a comma delimited list

    Thanks dflak! Apparently you have helped me on multiple occasions as the forum won't let me add to your reputation. It says "You must spread some reputation around before giving it to dflak again". Just know that I appreciate your help and this worked fantastically and was really easy to follow.

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: How to create a data validation list using VBA and a comma delimited list

    LOL! I wouldn't worry about the rep. I got enough points. I cleaned up what I gave you a bit and added it to my library of modules that I import from time to time. I have over 120 modules, but in reality only use about 10 of them routinely. I have no idea when this one will come in handy.

  5. #5
    Forum Contributor
    Join Date
    09-11-2014
    Location
    Eugene, Oregon
    MS-Off Ver
    MS EXCEL 2010
    Posts
    210

    Re: How to create a data validation list using VBA and a comma delimited list

    I am running into a bit of a snag with the above code. I got the code to work but I am struggling to add some additional code that will automatically display the 1st item in the list. Any ideas on how to modify the code to pick the first item in the drop down? Also if I change this from a Sub() to a Private Sub() will that run the VBA when opening the workbook? I am hoping that it runs when the workbook opens and then chooses the first item from the drop down list. Thanks in advance.

    Please Login or Register  to view this content.

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to create a data validation list using VBA and a comma delimited list

    Perhaps this
    Please Login or Register  to view this content.
    Also just be aware that if your string is longer than 255 characters, you’ll get a corrupt load message when reopening the file and the data validation will be removed.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  7. #7
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: How to create a data validation list using VBA and a comma delimited list

    The simplest way to run the code on workbook open is to go to the VB Editor, double click on ThisWorkBook and paste in.

    Please Login or Register  to view this content.
    With the appropriate sheet name, cell name and Lookup_List name.

+ 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. Convert columns with Xs to comma delimited list
    By ThumperStrauss in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-12-2018, 12:58 PM
  2. [SOLVED] how to use data validation with a delimited list (or use multiple columns)
    By dmcgov in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-14-2016, 10:39 AM
  3. [SOLVED] Data in Column A to Comma Delimited List
    By webdivx in forum Excel General
    Replies: 5
    Last Post: 07-11-2013, 02:16 PM
  4. Replies: 5
    Last Post: 01-31-2013, 01:03 PM
  5. Replies: 0
    Last Post: 01-09-2013, 11:44 AM
  6. Replies: 3
    Last Post: 07-20-2012, 09:52 AM
  7. Button that creates delimited comma list
    By aegliveinterns in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-25-2010, 08:48 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