分享: 使用者在下拉選單輸入資料後 自動於下拉選單中顯示對應的資料
- 帖子
- 47
- 主題
- 19
- 精華
- 0
- 積分
- 82
- 點名
- 0
- 作業系統
- win
- 軟體版本
- xp
- 閱讀權限
- 20
- 註冊時間
- 2014-7-4
- 最後登錄
- 2021-9-4
|
分享: 使用者在下拉選單輸入資料後 自動於下拉選單中顯示對應的資料
本帖最後由 ciboybj 於 2019-5-16 00:42 編輯
以下程式
可以讓使用者在下拉式選單ComboBox中輸入單字時
自動去比對欄1中具有相同字串的儲存格內容
舉例來說,欄1填有多個公司名
如下圖所示,當使用者於下拉選單中輸入「台」 則下拉選單的下方將自動產生出「台」開頭的公司名
- Private Sub ComboBox1_Change()
- Dim str_input_len As Integer
- Dim endCol As Integer
- Dim str_cellText As String
- Dim str_output As String
-
- endCol = Range("a65536").End(xlUp).Row
- str_input_len = Len(ComboBox1.Text)
-
- ComboBox1.List = Array()
-
- For i = 1 To endCol Step 1
- str_output = ""
- str_cellText = Left(Cells(i, 1).Text, str_input_len)
- If str_cellText = ComboBox1.Text Then
- str_output = Cells(i, 1).Text
- ComboBox1.AddItem str_output
- SendKeys "%{Down}"
- End If
- Next
- End Sub
複製代碼 |
|
|
|
|
|
|