Dynamically set ListFillRange in Excel ComboBox

后端 未结 7 800
忘了有多久
忘了有多久 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:31

    This is working fine on Excel 2010:

    I have a list of items in column "AN" that changes (get bigger/shorter) every week. I have created a variable called "c" which contains the number of items in the list. By using this variable, the ComboBox (positioned on cells S7:U7) will now dinamically show the items actually contained in the list (no empty spaces or missing items in the combobox).

    Code:

    Dim rng As Range
    
    Set rng = ActiveSheet.Range("S7:U7")
    ActiveSheet.DropDowns.Add(rng.Left, rng.Top, rng.Width, rng.Height).Select
    With Selection
        .ListFillRange = "AN1:AN" & c
        .LinkedCell = "$V$7"
        .DropDownLines = 8
        .Display3DShading = False
    End With
    

提交回复
热议问题