有一表單名稱為A表單,該表單內有二個欄位皆為下拉式選單,分別為城市、鄉鎮區二個欄位。當選擇城市欄值為新北市時,連動鄉鎮區欄位值供挑選,請問城市下拉選單Afterupdate事件,VBA如何書寫?

2018-12-30 10:40 pm

回答 (1)

2019-01-04 12:21 pm
Private Sub ComboBox1_AfterUpdate()
ComboBox2.Clear
CxxA = ComboBox1.Value
With Sheets("資料表")
For i = 2 To .[A1048576].End(3).Row
Cb = .Cells(i, 1)
If Cb = CxxA Then
ComboBox2.AddItem Cells(i, 2)
End If
Next
End With
End Sub

Private Sub UserForm_Initialize()
With Sheets("資料表")
Set Rng = CreateObject("Scripting.Dictionary")
For Each Cb In .Range("A2:A" & .[A1048576].End(3).Row)
If Not Rng.Exists(Cb.Value) Then
Rng.Add Cb.Value, Cb.Value
End If
Next Cb
End With
Me.ComboBox1.List = Rng.keys
End Sub


收錄日期: 2021-05-03 06:58:14
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20181230144059AAmbzyY

檢視 Wayback Machine 備份