2012-10-21 621 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 
相关问题