从其他列表中筛选Excel

时间:2012-06-14 13:55:22

标签: excel drop-down-menu filter

我在excel中有2个列表。第一个用于搜索(我想要有dropbox),第二个用于数据。 在第二个列表中,我已经过滤了数据但我现在要做的是从第一个列表中给出的参数进行过滤。

如何在首页上传输过滤器标题?

Search list and list with data

我想在' Search'上选择品牌。列表和结果将在'行'过滤列表。

1 个答案:

答案 0 :(得分:1)

如果没有VBA,我想不出办法做到这一点。当然很想知道是否有办法,所以也许别人可以插手。

那就是说,这是一个小型的VBA程序,可以得到你想要的东西。它的工作原理是根据“搜索”表格中“品牌”下拉框的更改。按照以下步骤实施:

  • 一旦在Excel中按下键盘上的Ctrl + F11。这打开了VBE
  • 在项目 - 左上角的VBAProject窗口中,单击“参考搜索表”的对象
  • 将以下代码粘贴到右侧的大窗口中,引用该表格。
  • 如果使用XL2007或更高版本,请务必将文件另存为.xlsm文件(Excel-Macro Enabled File)。

    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim wksFilter As Worksheet, wks As Worksheet
    Dim rngFilter As Range
    
    'replace "A6" with the cell where the Brand dropdown is
    If Target.Address = "$A$6" Then
    
        Set wks = Sheets(Target.Parent.Name)
        Set wksFilter = Sheets("Rows")
    
        'may need to adjust the number 1 to match the exact location of your Search Column in the rows sheet
        wksFilter.UsedRange.AutoFilter 1, wks.Range(Target.Address)
    
    End If
    

    End Sub