从命名范围填充组合框 [英] Populating combobox from named ranges
问题描述
我已使用excel的验证公式创建了三个相关的下拉列表。
这样做的好处是可以轻松添加更多选项,并且下拉列表会自动更新。其结构如下所示(每个范围的名称与列标题相同)。
I have created three dependent drop down lists using excel's validation formula. The benefit of this is that it is easy to add more options and the dropdown list updates automatically. The structure for this is seen below (where each range is given the same name as the column header).
是否可以创建相同的效果使用组合框。我可以找到一些示例,这些示例可以从手中填充组合框,而不能从命名范围自动填充组合框
Is it possible to create the same effect using combo boxes. I can find examples of populating a combo box from hand but not automatically from named ranges
推荐答案
您可以在此处进行练习。
Here is something you can practice with.
使用worksheet_selection更改事件填充,标题范围称为标题
Populate with a worksheet_selection Change event, the headers range is named "Headers"
标题下方的区域根据标题命名名称。
The range below the headers are named according to the header names.
更改combobox1以填充combobox2
Change combobox1 to populate combobox2
Private Sub ComboBox1_Change()
Dim s As String
s = ComboBox1
Me.ComboBox2.List = Range(s).Value
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ComboBox1.List = Application.WorksheetFunction.Transpose(Range("Headers"))
End Sub
这篇关于从命名范围填充组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!