我有一个Excel,有两张纸。
名为“Items”的工作表包含一个名为“ItemsTable”的具有多个条目的列表。有多少人并不重要。我在它旁边添加了一个“过滤器”按钮以供以后用途:
Items sheet
其次,我有一个名为“Data”的工作表,其中有一个名为“DataTable”的表。在这个表中,我从ItemsTable中随机添加了条目(每个单元格都是一个下拉列表,我可以从ItemsTable中选择一个条目)。可以有空白单元格。填充时看起来像这样:
Data sheet
到目前为止的可用数据。我想从这里提取一些数据。首先,我手动过滤“Items”表中我想要使用的一些项目,例如这次只过滤梨和香蕉:
Items sheet filtered
现在我想要它做的是,当我点击“过滤器”按钮时,它应该接受选中的项目(在本例中为2),并检查这些项目是否同时出现在DataTable的行中。它们必须同时出现在一行上,在那一行上以任何顺序出现,只要它们都出现(或者我选择选择的项目数量)。这个想法是,我想创建一个名为“Stats”的新工作表(或者删除它的内容,如果这个工作表已经存在),并在该工作表上创建一个与“DataTable”表相同标题的新表,并将所有符合条件的行添加到新创建的表中。
因此,在这种情况下,将创建“Stats”工作表(或清除内容,如果它存在),并在其中添加一个表,其中包含以下行:
Stats sheet
我在vba中为这个过滤器按钮创建了一个宏:
Sub Filter()
End Sub
我已经尝试了很多方法来使用数组和循环,但每次都遇到一些问题。我甚至在尝试只使用我使用SpecialCells(xlCellTypeVisible)过滤的选定项时遇到了问题。我不会粘贴我尝试过的代码,因为它可能是无用的。有没有人可以帮我写一些必要的代码来执行这个命令?我会永远感激,因为我真的需要这个工作。
2条答案
按热度按时间xwbd5t1u1#
取过滤数据
zaq34kh62#
一步一步在一个子
第二个版本与精确搜索