从行数组填充ListBox(Populating a ListBox from row array)

编程入门 行业动态 更新时间:2024-10-25 15:28:10
行数组填充ListBox(Populating a ListBox from row array)

任何人都可以解释我的代码有什么问题吗? 我试图在行数组上填充ListBox。 我得到运行时错误438.对象不支持此属性或方法,但不清楚我编码错误。

Private Sub ListBox1_Click() Dim LastRow As Long With Sheets("TempList") LastRow = .Range("A" & Rows.Count).End(xlUp).Row End With Sheets("tblSurveyMatches").ListBox1.RowSource = Sheets("TempList").Range("A2" & LastRow) End Sub

Can anyone explain what's wrong with my code? I am trying to populate a ListBox on an array of rows. I get the run-time error 438. Object doesn't support this property or method, but it is unclear what I have coded wrong.

Private Sub ListBox1_Click() Dim LastRow As Long With Sheets("TempList") LastRow = .Range("A" & Rows.Count).End(xlUp).Row End With Sheets("tblSurveyMatches").ListBox1.RowSource = Sheets("TempList").Range("A2" & LastRow) End Sub

最满意答案

如果这是工作表上的ActiveX控件,这将起作用,您需要使用ListFillRange而不是RowSource 。

Sheets("tblSurveyMatches").ListBox1.ListFillRange= Sheets("TempList").Name & "!" & Range("A2:A" & LastRow).Address

请注意,通常最好将Range限定为工作表,但在这种情况下,因为我们只需要一个地址字符串,所以在这里并不重要。

Provided this is an ActiveX control on your sheet, this will work, you need to use ListFillRange instead of RowSource.

Sheets("tblSurveyMatches").ListBox1.ListFillRange= Sheets("TempList").Name & "!" & Range("A2:A" & LastRow).Address

Note that it is normally best practice to qualify the Range to a worksheet, but in this case since all we need is an address string, it's not as important here.

更多推荐

本文发布于:2023-07-29 18:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1318662.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:行数   ListBox   Populating   row   array

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!