如何解决在列表框上显示项目
我有下面的列表来显示D,E,F,G / N,O,P,Q / S,T,U,V ...等范围内的项目
这个想法是从列表框中选择范围内的项目:C2,H2,M2等,然后在第二个列表中显示它们的关联值:
我出于相同目的使用了此代码。区别在于我只有两列要显示。我试图编辑代码以在四列上显示所有数据:
Private Sub ListBox1_Click()
Dim sCol!
Dim Y%,X%
ListBox2.Clear
sCol = 3 + (Me.ListBox1.ListIndex * 2)
With Worksheets("Cycle_Vie_M1")
For X = 3 To .Cells(Rows.Count,sCol).End(xlUp).Row
ListBox2.AddItem .Cells(X,sCol).Value
' MsgBox .Cells(X,sCol).Value
ListBox2.List(ListBox2.ListCount - 1,1) = .Cells(X,sCol + 1).Value
ListBox2.List(ListBox2.ListCount - 1,2) = .Cells(X,sCol + 2).Value
ListBox2.List(ListBox2.ListCount - 1,3) = .Cells(X,sCol + 3).Value
Next X
End With
End Sub
解决方法
正在工作,这里是正确的代码:
Private Sub ListBox1_Click()
Dim sCol!
Dim Y%,X%
ListBox2.Clear
ListBox2.ColumnCount = 5
sCol = 3 + (Me.ListBox1.ListIndex * 5)
With Worksheets("Cycle_Vie_M1")
For X = 2 To .Cells(Rows.Count,sCol).End(xlUp).Row
ListBox2.AddItem .Cells(X,sCol).Value
' MsgBox .Cells(X,sCol).Value
ListBox2.List(ListBox2.ListCount - 1,1) = .Cells(X,sCol + 1).Value
ListBox2.List(ListBox2.ListCount - 1,2) = .Cells(X,sCol + 2).Value
ListBox2.List(ListBox2.ListCount - 1,3) = .Cells(X,sCol + 3).Value
ListBox2.List(ListBox2.ListCount - 1,4) = .Cells(X,sCol + 4).Value
Next X
End With
End Sub
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。