每当我从当前组合框中单击另一个组合框的下拉按钮并从下拉列表中选择一个项目时,组合框字段将显示为空白,我必须重新单击下拉列表并选择该项目才能将值放入组合框字段。
但是,当我在单击该组合框的下拉菜单之前先单击组合框字段时,从列表中选择一个项目将立即将所选项目的值放入组合框。
组合框的代码如下所示:
Private Sub cbxSupplier_AfterUpdate()
Dim Supplier_col As Long
ThisWorkbook.Worksheets("List_Box").ListObjects("tblFoilInfoHelper").DataBodyRange.ClearContents
Set filteredRangeFoilProfile = Nothing
lbxFoilInfoDisplay.RowSource = vbNullString
Supplier_col = ThisWorkbook.Worksheets("Foil Profile").ListObjects("tblFoilProfile").ListColumns("SUPPLIER").Index
If Len(Trim(cbxSupplier)) = 0 Then
filterRangeFoilProfile.AutoFilter Field:=Supplier_col
Else
filterRangeFoilProfile.AutoFilter Field:=Supplier_col, Criteria1:=cbxSupplier.Text
End If
On Error Resume Next
Set filteredRangeFoilProfile = Intersect(filterRangeFoilProfile, filterRangeFoilProfile.Offset(1, 0)).SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not filteredRangeFoilProfile Is Nothing Then
ThisWorkbook.Worksheets("Foil Profile").ListObjects("tblFoilProfile").DataBodyRange.SpecialCells(xlCellTypeVisible).Copy
ThisWorkbook.Worksheets("List_Box").Cells(2, 1).PasteSpecial
lbxFoilInfoDisplay.RowSource = "List_Box!A2:" & Col_Letter(TotalColumnsCount("Foil Purchases.xlsm", "List_Box")) & TotalRowsCount("Foil Purchases.xlsm", "List_Box", "tblFoilInfoHelper")
Call Dynamic_cbx
End If
End Sub
我相信Call Dynamic_cbx
模块不是其原因,因为我已将其注释掉,并且问题仍然相同。