组合框 ListFillRange VBA
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22426740/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ComboBox ListFillRange VBA
提问by user3423641
I am quite new to VBA for Excel and i'm trying to make a ComboBox
and fill it with values from a specific range. I got the code for the box itself somewhere from the internet and added some things as the ListFillRange
to it. Problem is that the list of the ComboBox
only has the value of the first cell of the range I specify, whatever I try. I searched all over the internet and can't find a solution to this. I put the box in a separate macro just to test what is the problem. Here is the code:
我对 Excel 的 VBA 很陌生,我正在尝试制作一个ComboBox
并用特定范围的值填充它。我从互联网的某个地方获得了盒子本身的代码,并在其中添加了一些东西ListFillRange
。问题是唯一的列表ComboBox
具有我指定范围的第一个单元格的值,无论我尝试什么。我在互联网上搜索了所有内容,但找不到解决方案。我将盒子放在一个单独的宏中只是为了测试问题所在。这是代码:
Sub testme()
Dim box As OLEObject
Dim myRng As Range
'combobox from the Control toolbox toolbar
Set myRng = ActiveSheet.Range("a25")
With myRng
Set box = .Parent.OLEObjects.Add _
(ClassType:="Forms.ComboBox.1", _
Link:=False, _
DisplayAsIcon:=False, _
Left:=.Left, _
Top:=.Top, _
Width:=.Width, _
Height:=.Height)
End With
box.LinkedCell = "b20"
Dim gebied As Range
Set gebied = Range("$A:$I")
box.ListFillRange = gebied.Cells.Address
End Sub
采纳答案by Doug Glancy
The ListFillRange needs to be in one column. I don't think there's a way around that for a WorkSheet ActiveX ComboBox
, but I could be wrong. Try something like:
ListFillRange 需要在一列中。我认为 WorkSheet ActiveX 没有办法解决这个问题ComboBox
,但我可能是错的。尝试类似:
Set gebied = Range("$A:$A")
box.ListFillRange = gebied.Cells.Address