2012-10-21 522 views
0

我試圖更新基於在cbo_moduleCode所做的選擇組合框cbo_moduleName的。現在,用戶必須選擇組合框來進行選擇,但我希望在循環中找到的第一個值能夠「實時」自動填充。有關我如何實現這一點的任何想法?這是我到目前爲止的代碼:請選擇第二個組合框項基於項目選擇第一個組合框

Private Sub cbo_moduleCode_Change() 

    Dim lLoop As Long 
    ' Clear the comboboxes we are about to update 
    Me.cbo_moduleName.Clear 

    ' Loop through the worksheet and test each row 
    For lLoop = 1 To Sheets("lookupModule").Range("A" & Sheets("lookupModule").Rows.Count).End(xlUp).Row 
     ' If the row's column A matches the combobox then add the corresponding values to other combos 
     If Sheets("lookupModule").Range("A" & lLoop).Value = Me.cbo_moduleCode.Value Then 
      Me.cbo_moduleName.AddItem Sheets("lookupModule").Range("B" & lLoop).Value 
     End If 
    Next lLoop 

End Sub 
+0

你說的意思是「對飛」 ? – shahkalpesh

+0

'cbo_moduleName'值保持爲空,直到用戶選擇下拉菜單以查看選項。我想'cbo_moduleName'實時更新,用戶在'cbo_moduleCode'中選擇。 – methuselah

+1

是不是你的代碼在做什麼?即當cbo_moduleCode中的選擇發生變化時,cbo_moduleCode_Change()不會觸發事件? – shahkalpesh

回答

1

要選擇的cbo_moduleName的第一個項目時cbo_moduleCode改變用戶的選擇,這裏是代碼

If Me.cbo_moduleName.ListCount > 0 Then 
    Me.cbo_moduleName.ListIndex = -1 
End If 
相關問題