当表单关闭时,我正在尝试“重置”Excel VBA 中的列表框。目前,当我使用 userform1.hide 函数时,表单会消失,但是当我使用 .show 函数再次打开它时,它仍然有之前的选择。作为对此相对较新的人,任何人都可以提供帮助吗?
列表框的代码如下:
Sub CommandButton1_Click()
'Filter by Country
Dim item As Long, dict As Object
Dim wsData As Worksheet
Set wsData = Sheets("TPID")
Set dict = CreateObject("Scripting.Dictionary")
With ListBox1
For item = 0 To .ListCount - 1
If .Selected(item) Then dict(.List(item)) = Empty
Next item
End With
With wsData.ListObjects("Table_ExternalData_1").Range
.AutoFilter Field:=1
If dict.Count Then _
.AutoFilter Field:=1, criteria1:=dict.keys, Operator:=xlFilterValues
End With
'Filter by Continent
Dim item1 As Long, dict1 As Object
Dim wsData1 As Worksheet
Set wsData1 = Sheets("TPID")
Set dict1 = CreateObject("Scripting.Dictionary")
With ListBox2
For item1 = 0 To .ListCount - 1
If .Selected(item1) Then dict1(.List(item1)) = Empty
Next item1
End With
With wsData1.ListObjects("Table_ExternalData_1").Range
.AutoFilter Field:=4
If dict1.Count Then _
.AutoFilter Field:=4, criteria1:=dict1.keys, Operator:=xlFilterValues
End With
End Sub
先谢谢大家了