【发布时间】:2017-01-25 17:45:10
【问题描述】:
我的工作表中有一个带有动态搜索的组合框,动态搜索是通过在另一个工作表上的列表中搜索键入的字母来完成的。搜索是通过excel公式完成的。该列表是一个定义的范围,然后组合框 listfillrange 设置为命名范围。 当我键入下拉列表时,对于某些项目,组合框允许我从列表中进行选择,而对于其他项目,选择会在我选择时消失。我试图弄清楚为什么这些项目会消失。列表很长(10,000 项),所以运行起来有点慢,但我不确定这是否是问题所在。
我该如何解决这样的问题?有没有办法为下拉列表中的鼠标点击选择定义一个变量?
提前致谢, 大理
这是我的代码:
Private Sub ComboBox1_Change()
Sheets("PS").EnableCalculation = True
ComboBox1.ListFillRange = "DropDownList"
ComboBox1.DropDown
End Sub
Private Sub CommandButton21_Click()
Dim PS As Worksheet
Application.ScreenUpdating = False
Application.ErrorCheckingOptions.BackgroundChecking = False
Sheets("PharmaSoft").Select
Set PS = Sheets("PS")
SelectionA = PS.Range("J2").Value
If ComboBox1.Value = SelectionA Then
Range("J19") = "Pharmacy purchase price"
Range("N19") = PS.Range("K2")
Range("O19") = "ILS"
Range("J21") = "Pharmacy selling price Incl.VAT"
Range("N21") = PS.Range("L2")
Range("O21") = "ILS"
Range("J23") = "Package size"
Range("N23") = PS.Range("M2")
Range("J19:O23").Select
With Selection.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
Selection.Font.Bold = True
Application.ScreenUpdating = True
Range("N19").Errors.Item(1).Ignore = True
Range("N21").Errors.Item(1).Ignore = True
Range("N23").Errors.Item(1).Ignore = True
Else
MsgBox "Please select a product", vbCritical, "Error"
End If
Sheets("PS").EnableCalculation = False
End Sub
Private Sub CommandButton22_Click()
Application.ScreenUpdating = False
Sheets("PharmaSoft").Select
ComboBox1.Value = Null
Range("J19:O23").Value = Null
Application.ScreenUpdating = True
End Sub
Also the code for the workbook:
Private Sub Workbook_Open()
Sheets("PharmaSoft").Select
Application.ScreenUpdating = False
Sheets("PharmaSoft").ComboBox1.Value = Null
Range("J19:O23").Value = Null
Application.ScreenUpdating = True
End Sub
【问题讨论】:
-
请添加一些数据示例或屏幕截图和您的代码
-
那么您使用的是什么类型的控件以及什么代码在哪里?我的意思是:ComboBox1 和所有按钮 ActiveX 控件还是 Forms 控件? “PS”是放置 ComboBox1 的工作表的名称吗? “PS”表属于哪个工作簿?按钮放置在哪些工作表中?
Workbook_Open()属于哪个工作簿? -
我只使用 ActiveX 控件而不是表单。代码在一个名为“Pharmasoft”的工作表中,我在其中显示了一种带有按钮的谷歌搜索字段,用于搜索和清除数据。“PS”是项目列表和计算组合框列表的位置。为整个工作簿定义的 workbook_open。
-
那么“另一个工作表”是什么?