Dynamically set ListFillRange in Excel ComboBox

后端 未结 7 769
忘了有多久
忘了有多久 2020-12-01 22:40

I tried doing something like:

 cmbMyBox.ListFillRange = \"E2\"

But the combobox does not seem to populate.

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 23:26

    I was facing similar issue, not being able to populate the ActiveX ComboBox with list reference peeked from a cell's validation rule.

    Similarly to Firedrawndagger's own solution I went for manually translating the validation rule to a format that is understood by the .ListFillRange. I realised also, that it needs to be in a Workbook-scope format, otherwise the call will not work from other sheets.

    This works with All validation source formats, including: $A$1 / =NamedRange / =INDIRECT("Table1[Col2]") The translation was:

    Dim xStr As String        
    xStr = Target.Validation.Formula1
    xStr = Right(xStr, Len(xStr) - 1)
    xStr = Split(Range(xStr).Address(, , , True), "]")(1)
    '...other irrelevant code
    .ListFillRange = xStr
    

提交回复
热议问题