我可以在Excel VBA中改变combobox.list的范围吗?

问题描述 投票:0回答:1

在 Excel VBA 中是否有任何选项允许我改变 combobox 的范围?请看示例

我想把VariantVariant(0到3,0到5)中的数字5改一下。

Combobox中填入了这段代码。

Private Sub UserForm_Activate()

Dim x As Range
    With Worksheets("Distributori")
      Set x = .Range("A2", .Range("F1000").End(xlUp))
End With

ComboBox1.RowSource = "Distributori!" & x.Address
ComboBox1.ListIndex = 0
Me.ComboBox1.TextColumn = 2

End Sub

excel vba excel-vba
1个回答
0
投票

请尝试下一个(改编)代码。

Dim x As Range, arrList As Variant
    With Worksheets("Distributori")
      Set x = .Range("A2", .Range("F1000").End(xlUp))
    End With
    arrList = x.Value
    With ComboBox1
        .ColumnCount = 6
        .list = arrList
        .ListIndex = 0
        .TextColumn = 2
    End With
© www.soinside.com 2019 - 2024. All rights reserved.