有兩個ListBox, 一個是單號(ListBox2), 一個是單號明細(ListBox1),都可以複選, 請詳附件[attach]15884[/attach]
想請問版上高手, ListBox2的程式是否有更好的寫法?
我目前寫法是:
Private Sub ListBox2_Change()
Dim lrow, irow, ai As Integer
Sheets("login").ListBox1.Clear
[A9:E19] = ""
With ListBox2
For lrow = 0 To .ListCount - 1
If .Selected(lrow) Then
With Sheets(Sh)
ai = 2
Do While .Cells(ai, "A") <> ""
If .Cells(ai, "A") = ListBox2.List(lrow, 0) Then
With ListBox1
.AddItem
irow = .ListCount
.List(irow - 1, 0) = Sheets(Sh).Cells(ai, "A")
.List(irow - 1, 1) = Sheets(Sh).Cells(ai, "B")
.List(irow - 1, 2) = Sheets(Sh).Cells(ai, "C")
.List(irow - 1, 3) = Sheets(Sh).Cells(ai, "D")
.List(irow - 1, 4) = Sheets(Sh).Cells(ai, "E")
End With
End If
ai = ai + 1
Loop
End With
End If
Next
End With
Application.EnableEvents = True
End Sub作者: c_c_lai 時間: 2013-8-30 08:50
回復 23#yliu
請修改如下
Dim lrow, irow, ai As Integer, AR(), S As String -> Dim AR
If UBound(AR) > -1 Then ReDim -> If .ListCount > 0 Then ReDim作者: yliu 時間: 2013-9-4 23:00