- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
2#
發表於 2012-6-1 09:03
| 只看該作者
回復 1# man65boy
ListBox1 更換為 ComboBox1
ListBox2 更換為 ComboBox2- Dim xlSh As Worksheet
- Private Sub UserForm_Initialize()
- Set xlSh = Sheets("總表")
- TextBox1_Change '
- End Sub
- Private Sub CommandButton1_Click()
- Dim Rng As Range, xi As Integer
- If ComboBox1.ListIndex > -1 And ComboBox2.ListIndex > -1 Then
- With xlSh
- xi = 2
- Do While .Cells(xi, "C") <> ""
- If .Cells(xi, "B").Text = ComboBox2 And .Cells(xi, "C") = ComboBox1 Then
- If Rng Is Nothing Then
- Set Rng = .Range(.Cells(xi, "d"), .Cells(xi, "i"))
- Else
- Set Rng = Union(Rng, .Range(.Cells(xi, "d"), .Cells(xi, "i")))
- End If
- End If
- xi = xi + 1
- Loop
- Rng.Copy
- Sheets("報價單列印").Cells(Rows.Count, "b").End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
- End With
- Else
- MsgBox "客戶名稱 或 日期 ??? "
- End If
- End Sub
- Private Sub CommandButton2_Click()
- Unload UserForm1
- End Sub
- Private Sub TextBox1_Change()
- Dim xi As Integer, xlString As String
- With xlSh
- xi = 2
- Do While .Cells(xi, "C") <> ""
- If .Cells(xi, "C") Like "*" & TextBox1 & "*" Then
- If InStr(xlString, "," & .Cells(xi, "C") & ",") = 0 Then
- xlString = xlString & "," & .Cells(xi, "C") & ","
- End If
- End If
- xi = xi + 1
- Loop
- End With
- If xlString = "" Then 'TextBox1的內容找不到
- ComboBox1.Clear
- ComboBox2.Clear
- Exit Sub
- End If
- With ComboBox1
- .List = Split(Mid(xlString, 2, Len(xlString) - 2), ",,")
- .Value = .List(0)
- End With
- End Sub
- Private Sub ComboBox1_Change()
- Dim xi As Integer, xlString As String
- If ComboBox1.ListIndex > -1 Then
- '控制項.ListIndex = -1 控制項的 值或選項 不在List內
- With xlSh
- xi = 2
- Do While .Cells(xi, "C") <> ""
- If .Cells(xi, "C") = ComboBox1 Then
- If InStr(xlString, "," & .Cells(xi, "B") & ",") = 0 Then
- xlString = xlString & "," & .Cells(xi, "B") & ","
- End If
- End If
- xi = xi + 1
- Loop
- End With
- With ComboBox2
- .List = Split(Mid(xlString, 2, Len(xlString) - 2), ",,")
- .Value = .List(0)
- End With
- ElseIf ComboBox1.ListIndex = -1 Then
- ComboBox2.Clear
- End If
- End Sub
複製代碼 |
|