- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
本帖最後由 GBKEE 於 2013-9-4 11:14 編輯
回復 12# yliu - Private Sub ListBox2_Change()
- Dim lrow, irow, ai As Integer, AR, S As String
- With ListBox1
- AR = .List '.List-> ( 0 TO .ListCount - 1, 0 TO 9) ListBox的ColumnCount 屬性 最多只能有 10 行 (0 到 9)。
- '這ListBox1只有4行資料,後面的5行-9行 = Null,使用Index 函數會錯誤
- If .ListCount > 0 Then ReDim Preserve AR(0 To .ListCount - 1, 0 To .ColumnCount - 1) '消除 後面的5行-9行的 Null
- For lrow = 0 To .ListCount - 1
- If .Selected(lrow) Then
- S = S & Join(Application.Index(AR, lrow + IIf(UBound(AR) = 0, 0, 1)), "") '紀錄已勾選的資料
- End If
- Next
- .Clear
- End With
- [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")
- If InStr(S, Application.Phonetic(Sheets(Sh).Cells(ai, "A").Resize(, 5))) Then '比對: 紀錄已勾選的資料
- .Selected(.ListCount - 1) = True
- End If
- End With
- End If
- ai = ai + 1
- Loop
- End With
- End If
- Next
- End With
- End Sub
複製代碼 |
|