Excel Dynamic Drop Down Using Comma Delimited Data

2019-06-09 20:42发布

问题:

I'm trying to develop an internal use form where individuals can make a selection from a drop down list that will filter another drop down list based on their choice. I have reviewed the options for indirect, dependent dynamic lists, but this does not seem feasible for a list that will potentially contain hundreds of different values with thousands (or more) permutations. The group before me created a bunch of macros to solve this issue, but I have to believe there is a simpler way to manage the information.

Is there a way that you can develop a drop down list from within a single cell? Any insight would be greatly appreciated.

UPDATE: Using part of Gary's code, I was able to solve part of my issue:

Sub Marco4()
    r = Range("H24").Value
    s = Application.VLookup(r, Worksheets("Data").Range("R2:T4"), 3, False)
    Range("B25").Select
    With ActiveCell.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:=s
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
End Sub

I'd like to use an existing drop down item instead of having the cell turn into a drop down itself, if possible.

回答1:

Say cell C2 contains a comma separated string. This simple macro will set the Data Validation of the activecell to that string:

Sub LeeCarver()
    Dim s As String
    s = Range("C2").Value
    With ActiveCell.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:=s
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
End Sub

For example: