多列列表框 - 添加项目:无效或不合格的引用
Multicolumn listbox - Add item: Invalid or unqualified reference
我需要你的帮助。
试图用稍后要选择的值填充用户表单列表框..
但是我在列表框上遇到了困难,当我为调试做一个消息框时它工作得很好,但是当我尝试添加项目时它失败了,请告诉我哪里出错了..
' Option Explicit
Private Sub UserForm_Activate()
Dim rowCount As Integer
Dim MyRows As Integer
Dim i As Integer
Dim sh As Worksheet
Set sh = Sheets("Data2020")
sh.Select
Me.PendingList.ColumnCount = 3
Me.PendingList.ColumnWidths = "50;50"
i = 1
rowCount = sh.Range("Y1", sh.Range("Y1").End(xlDown)).rows.Count
While Me.PendingList
For MyRows = 1 To rowCount
If sh.Cells(MyRows, 25) = 0 Then
' MsgBox ("" & MyRows & " " & sh.Cells(MyRows, 2).Value) WORKS..
.AddItem
' Testing with numbers, incase its the sheet that is failing me.
.List(i, 0) = MyRows ' sh.Cells(MyRows, 1).Value
.List(i, 1) = MyRows + 1 ' sh.Cells(MyRows, 2).Value
i = i + 1
End If
Next MyRows
Wend
Unload OpenPending
End Sub
使用 AddItem
,您指定调用的第一列,然后指定其余列:
.AddItem sh.Cells(MyRows, 1).Value
.List(.ListCount - 1, 1) = sh.Cells(MyRows, 2).Value
我需要你的帮助。 试图用稍后要选择的值填充用户表单列表框..
但是我在列表框上遇到了困难,当我为调试做一个消息框时它工作得很好,但是当我尝试添加项目时它失败了,请告诉我哪里出错了..
' Option Explicit
Private Sub UserForm_Activate()
Dim rowCount As Integer
Dim MyRows As Integer
Dim i As Integer
Dim sh As Worksheet
Set sh = Sheets("Data2020")
sh.Select
Me.PendingList.ColumnCount = 3
Me.PendingList.ColumnWidths = "50;50"
i = 1
rowCount = sh.Range("Y1", sh.Range("Y1").End(xlDown)).rows.Count
While Me.PendingList
For MyRows = 1 To rowCount
If sh.Cells(MyRows, 25) = 0 Then
' MsgBox ("" & MyRows & " " & sh.Cells(MyRows, 2).Value) WORKS..
.AddItem
' Testing with numbers, incase its the sheet that is failing me.
.List(i, 0) = MyRows ' sh.Cells(MyRows, 1).Value
.List(i, 1) = MyRows + 1 ' sh.Cells(MyRows, 2).Value
i = i + 1
End If
Next MyRows
Wend
Unload OpenPending
End Sub
使用 AddItem
,您指定调用的第一列,然后指定其余列:
.AddItem sh.Cells(MyRows, 1).Value
.List(.ListCount - 1, 1) = sh.Cells(MyRows, 2).Value