VBAcomboboxoDictionary方法重复值
所以我试图通过名称和date列表循环。 用户在表单中input一个名字,然后当他们点击下拉菜单时,它将填入适用于该名称的date。 我正在尝试使用oDictionary方法来说明重复。 然而,每次我点击下拉菜单时,他们都会加倍重新填充。 所以,如果他们点击下拉菜单,然后再点击它,每个date有两个值。
Private Sub cbCancelApptDate_DropButtonClick() Dim NamePop As String Dim NameRange As Range Dim cell As Range Dim Countcells As Integer NamePop = tbNewApptName.Value 'Search All Appointments If Sheets("All Appointments").Range("C3") = "" Then Set NameRange = Sheets("All Appointments").Range("C2:C2") Else Set NameRange = Sheets("All Appointments").Range("C2", Sheets("All Appointments").Range("C2").End(xlDown)) End If Dim oDictionary As Object Set oDictionary = CreateObject("Scripting.Dictionary") With Me.cbCancelApptDate For Each cell In NameRange If NamePop = cell.Value Then If oDictionary.exists(cell.Offset(, -2).Value) Then 'Do Nothing Else oDictionary.Add cell.Offset(, -2).Value, 0 .AddItem cell.Offset(, -2).Value End If End If Next cell End With
要使字典跨多个调用(点击)保存其内容,应将其声明为全局。
' outside any sub: Dim oDictionary As Object 'inside the sub: if oDictionary Is Nothing Then Set oDictionary = CreateObject("Scripting.Dictionary")
- 必须点击combobox的左侧才能工作
- 从一个模块中的集合获取值到userform中的combobox中
- 填写Excel +从Microsoft Sql Management Studio数据库表填充active x comobo框
- VBA用户界面:防止键盘上的COMBOBOX ESCAPE
- 数据validation和单元格中的combobox – Workbook_SheetChange事件不起作用
- Excel VBA – 级联下拉菜单清除/重置
- Excel VBA:添加数组以形成控件combobox
- 使用Excel VBA中的行值填充ComboBox
- 将ListObject列添加到Userformcombobox列表时出错