vba 来自另一张纸的 ListFillRange
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28199576/
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
ListFillRange from another sheet
提问by Matt
I'm trying to fill a combobox using .ListFillRange from another sheet however the list is not being populated.
我正在尝试使用另一张工作表中的 .ListFillRange 填充组合框,但未填充该列表。
I have the combobox on "sheet1" and the data on "sheet2" in the cells A2:A3000
我在“sheet1”上有组合框,在单元格 A2:A3000 中有“sheet2”上的数据
From sheet1 I have tried using:
从 sheet1 我尝试使用:
set ws = ThisWorkbook.Worksheets("sheet2")
set Rng = ws.Range("A2:A3000")
ComboBox.ListFillRange = ws.Range(Rng)
I have also tried
我也试过
ComboBox.ListFillRange = ws.Range("sheet2!A2:A3000")
However the combobox is not being populated, any suggestions?
但是组合框没有被填充,有什么建议吗?
采纳答案by Dick Kusleika
The ListFillRange is a string, so you need to pass in the address of the range. And since the range is on another sheet, you need to qualify that address. Fortunately, the Address property has an External argument.
ListFillRange 是一个字符串,所以需要传入范围的地址。由于该范围在另一张纸上,您需要限定该地址。幸运的是,Address 属性有一个 External 参数。
Sheet1.ComboBox1.ListFillRange = Sheet2.Range("A2:A3000").Address(, , , True)
The Address property will look like
Address 属性看起来像
?Sheet2.Range("A2:A3000").Address(, , , True)
[Book2]Sheet2!$A:$A00
But the control understands it and converts it.
但是控件理解它并转换它。
?sheet1.ComboBox1.ListFillRange
Sheet2!$A:$A00
Having said that, I never use ListFillRange. I prefer to fill the control myself using List or AddItem.
话虽如此,我从不使用 ListFillRange。我更喜欢使用 List 或 AddItem 自己填充控件。