Results 1 to 7 of 7

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

Threaded View

cmorten82 How to create a data... 06-13-2018, 11:27 AM
dflak Re: How to create a data... 06-13-2018, 01:59 PM
cmorten82 Re: How to create a data... 06-13-2018, 02:56 PM
dflak Re: How to create a data... 06-13-2018, 03:00 PM
cmorten82 Re: How to create a data... 06-13-2018, 07:35 PM
xlnitwit Re: How to create a data... 06-14-2018, 02:38 AM
dflak Re: How to create a data... 06-14-2018, 07:46 AM
  1. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    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.

    Sub CreateList(SheetName As String, CellName As String, LookupString As String)
    ' SheetName = Sheet where you want the drop-down list
    ' CellName = Address of the cell where you want the drop-down
    
    Dim Sh As Worksheet             ' General pointer to sheets in the workbook
    Dim shD As Worksheet            ' Pointer to the sheet on which you want the drop-down
    Dim ListString As String        ' List of the sheet names
    
    ' Initalize variables
    Set shD = Sheets(SheetName)
    ListString = ""
    
    
    
    ' "Remove" the trailing comma from the string
    ListString = LookupString
    
    ' Make the validation
    With shD.Range(CellName).Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=ListString
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
    End Sub
    
    Sub ApplyLookup()
    CreateList "Sheet1", "B2", Range("Lookup_List")
    End Sub
    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.

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