在Userform中过滤,ComboBox仅显示过滤后的数据

时间:2014-12-21 13:28:52

标签: excel excel-vba vba

我需要帮助ComboBoxes和过滤器,当我从ComboBox1设置过滤器("今天"或者#34;本周")并按下按钮,我想ComboBox2只显示过滤后的数据这是在第1列,怎么做?这是我的代码:

Private Sub CommandButton1_Click()

Dim rng As Range Set rng = Sheet1.Range("Database")
If ComboBox1.Value = "Today" Then With rng .AutoFilter Field:=2, Criteria1:= _ xlFilterToday, Operator:=xlFilterDynamic End With End If If ComboBox1.Value = "This Week" Then With rng .AutoFilter Field:=2, Criteria1:= _ xlFilterThisWeek, Operator:=xlFilterDynamic End With End If End Sub

0 个答案:

没有答案