根据下拉列表的值更新表

时间:2019-07-01 15:54:03

标签: excel vba

当前,我正在过滤带有下拉列表的表格。我想更新表而不是过滤器。如果可能的话,如何更改代码以实现最终目标。

Private Sub Worksheet_Change(ByVal target As Range)
   ' Cell with dropdown
   Const DropDown = "C4"
   ' Sheet with table
   Const TableSheet = "Data"
   ' Top left cell of range with table
   Const TableRange = "Data"
   If Not Intersect(Range(DropDown), target) Is Nothing Then
       Application.EnableEvents = False
       If Range(DropDown).Value = "" Then
           Worksheets(TableSheet).ShowAllData
       Else
           Worksheets(TableSheet).Range(TableRange).AutoFilter _
               Field:=1, Criteria1:=Range(DropDown).Value
       End If
       Application.EnableEvents = True
   End If
End Sub

0 个答案:

没有答案