现在我有一个看起来像这样的用户窗体:
我有一个如下所示的电子表格:
我在 UserForm_Initialize 事件中使用以下代码将自动筛选应用于我的数据。我需要在名为“boxPolicyList”的列表框中显示自动筛选的结果。
Worksheets("defaults").Select
Me.boxDateBegin.Value = ActiveSheet.Range("E4").Value
Me.boxDateEnd.Value = ActiveSheet.Range("F4").Value
Workbooks.Open Filename:="Z:\Stuff\production\production_database.xlsm"
Worksheets("policies").Select
With ActiveSheet
.AutoFilterMode = False
With .Range("A1:F1")
.AutoFilter
.AutoFilter field:=1, Criteria1:=">=" & Me.boxDateBegin.Value, _
Operator:=xlAnd, Criteria2:="<=" & Me.boxDateEnd.Value
.AutoFilter field:=3, Criteria1:="Bear River Mutual"
End With
End With
Me.txtTotalPolicies.Caption = ActiveSheet.Range("J1").Value
Me.txtTotalPremium.Caption = ActiveSheet.Range("H1").Value
Me.txtTotalPremium.Caption = Format(Me.txtTotalPremium.Caption, "$#,###,###.00")
Workbooks("production_database.xlsm").Activate
ActiveWorkbook.Save
ActiveWorkbook.Close
有谁知道如何做到这一点?