【說明】
使用者輸入錯誤的資料會造成維護上困擾,所以想限制使用者只能以選擇方式輸入資料。
【Sample】
1、把游標移到要輸入資料(1)的位置後按笑臉(2)帶出書名清單,選擇書名按滑鼠左鍵
2、資料輸入至儲存格
【作法】
1、建立工作表命名為「項目清單」,在A欄輸入需要的資料
2、建立工作表命名為「出售明細」,在A欄插入笑臉圖按
3、按ALT+F11進入VBA模式,並新增一個表單,表單包含1個ListBox
4、表單的程式碼設定
Private Sub ListBox1_Click()
If ActiveCell.Value <> "" Then
MsgBox "儲存格有值"
Else
ActiveCell.Value = ListBox1.Value
End If
Unload Me
End Sub
Private Sub UserForm_Activate()
Dim i As Integer
Dim ItemList As Variant
ItemList = Sheets("項目清單").Range("A2:A4").Value
For Each x In ItemList
ListBox1.AddItem x
Next x
End Sub
5、笑臉按右鍵,指定新增模組,模組內容設定如下
Sub 笑臉1_Click()
UserForm1.Show
End Sub
檔案下載
https://drive.google.com/file/d/1p7p4Tg82CdFGR_wuOH8_n9nAIy4Nk7nX/view?usp=sharing