【发布时间】:2014-06-20 14:45:54
【问题描述】:
我有一个包含三列的 excel 文件。 每一行都是唯一的。 这三列对应三个组合框。
当第一个组合框中的选项被选中时,我希望第二个组合框填充第二列中与第一个组合框中的选择相对应的项目。 即:
- Adam | Apple | Seed
- Adam | Apple | Core
- Adam | Orange | Peel
- Jess | Banana | Peel
- Jess | Mango | Pulp
- Jess | Orange | Seed
这里的第一列有数据 Adam,Jess。第一个组合框已经有两个独特的选项 Adam 和 Jess。
一旦用户选择了 Adam 或 Jess,第二个组合框应填充相应的水果名称。
例如。 Combobox1 = 亚当
然后 combobox2 ={Apple, Orange}
when either Apple / Orange are selected then the third combobox should have options correspoding to the first two comboboxes.
请注意,我的第一个组合框已经正确填充了数据:
Function UniqueList()
'Populate control with
'unique list.
Range("Names").AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Range("uniqueNames"), Unique:=True
'Set combo control's Row Source property.
Range("uniqueNames").RemoveDuplicates Columns:=1, Header:=xlNo
UserForm1.uniqueNameList.RowSource = Selection.CurrentRegion.Address
'Display user form.
UserForm1.Show
Selection.CurrentRegion.Clear
End Function
编辑:我基本上需要这样说: 用第一行等于 combobox1 的第二行的单元格填充第二个组合框。
【问题讨论】:
-
为什么不直接使用
ComboBox_Change事件? -
@chrisneilsen 我在网上找到了这个。 msdn.microsoft.com/en-us/library/…这会有帮助吗?
-
那是 .Net 的,不是 VBA 的,所以没有。