我收到错误"在列表框中填充数据时无法正确设置列表。请协助。
ListBox1.Clear
Dim vertical As String
lstRw = ThisWorkbook.Sheets(1).Range("A" & Rows.Count).End(xlUp).Row
Dim j As Integer
j = 0
For i = 2 To lstRw
If ComboBox4.Value = ThisWorkbook.Sheets(1).Range("A" & i).Value Then
Me.ListBox1.AddItem ThisWorkbook.Sheets(1).Range("A" & i).Value
Me.ListBox1.List(ListBox1.ListCount - 1, j) = ThisWorkbook.Sheets(1).Range("B" & i).Value
Me.ListBox1.List(ListBox1.ListCount - 1, j) = ThisWorkbook.Sheets(1).Range("C" & i).Value
Me.ListBox1.List(ListBox1.ListCount - 1, j) = ThisWorkbook.Sheets(1).Range("D" & i).Value
Me.ListBox1.List(ListBox1.ListCount - 1, j) = ThisWorkbook.Sheets(1).Range("E" & i).Value
Me.ListBox1.List(ListBox1.ListCount - 1, j) = ThisWorkbook.Sheets(1).Range("F" & i).Value
Me.ListBox1.List(ListBox1.ListCount - 1, j) = ThisWorkbook.Sheets(1).Range("G" & i).Value
j = j + 1
End If
Next i
答案 0 :(得分:1)
您需要为列表框指定ColumnCount。您还需要在添加的每个列之间增加变量j。在添加每个新行时,变量j也需要重置为1:
IWebHost