- 帖子
- 49
- 主題
- 8
- 精華
- 0
- 積分
- 63
- 點名
- 0
- 作業系統
- windows XP
- 軟體版本
- Office 2003
- 閱讀權限
- 20
- 性別
- 女
- 來自
- 高雄
- 註冊時間
- 2013-4-8
- 最後登錄
- 2013-10-30

|
有兩個ListBox, 一個是單號(ListBox2), 一個是單號明細(ListBox1),都可以複選, 請詳附件
ListBox問題(2).zip (23.22 KB)
想請問版上高手, 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 |
|