Excel Dynamic Drop Down Using Comma Delimited Data

℡╲_俬逩灬. 提交于 2019-12-10 11:58:19

问题


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:



来源:https://stackoverflow.com/questions/28324004/excel-dynamic-drop-down-using-comma-delimited-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!