如何在Excel用户自定义的窗体中实现省⼀市动态筛选查询

2025-03-10 21:53:46
推荐回答(3个)
回答1:

如果你的窗体(“组合框”吧?)能够设置“数据有效性”,可参考我之前的回答(二级下拉菜单):
http://zhidao.baidu.com/question/367298830.html

回答2:

图1的情况,代码如下。做好的已发送到你的邮箱。如果有问题可以再问我。^_^

Private Sub ComboBox1_change()
Arr1 = Range(Cells(1, 1), Cells(Cells(65536, 1).End(xlUp).Row, 2))
Set Dict1 = CreateObject("scripting.dictionary")
Dict1.RemoveAll
For i = LBound(Arr1) To UBound(Arr1)
If Arr1(i, 1) = ComboBox1.Value Then
Dict1.Add Arr1(i, 2), ""
End If
Next
ComboBox2.List = Dict1.keys
End Sub

Private Sub ComboBox2_change()
a = ComboBox1.Value
b = ComboBox2.Value
Unload Me
End Sub

Private Sub UserForm_Initialize()
Dim Arr1, Dict1
Arr1 = Range(Cells(1, 1), Cells(Cells(65536, 1).End(xlUp).Row, 2))
Set Dict1 = CreateObject("scripting.dictionary")
Dict1.RemoveAll
For i = LBound(Arr1) To UBound(Arr1)
If Not Dict1.exists(Arr1(i, 1)) Then
Dict1.Add Arr1(i, 1), ""
End If
Next
ComboBox1.List = Dict1.keys
End Sub

回答3:

留个QQ 发个样板给你?