[英]Filter Data in Workbook2 based on the cell value in cell values in Workbook1
I need a VBA code that will filter the data in Workbook2 based on the cell value in Workbook1.我需要一个 VBA 代码,它将根据 Workbook1 中的单元格值过滤 Workbook2 中的数据。
For Example: I need to pick up data from the cell under Filtered Data例如:我需要从过滤数据下的单元格中获取数据
Split the data if there are multiple values separated by semicolon and apply filter using xlOr operation in Workbook1.如果有多个值以分号分隔,则拆分数据并在 Workbook1 中使用 xlOr 操作应用过滤器。 The data which needs to be filtered will be dynamic based on the cell value.需要过滤的数据将根据单元格值动态变化。
The solution you are looking for is a simple Split function.您正在寻找的解决方案是一个简单的 Split function。
criterias = Split(ThisWorkbook.Worksheets(1).Cells(2, 1).Value, ";")
It splits the string in sheet 1 cell A2 into an array, it cuts at ";"它将工作表 1 单元格 A2 中的字符串拆分为一个数组,它在“;”处剪切and will just be an array.并且只是一个数组。 In thi case the Array will look like criterias=[A,B,C] When you got that string you can use autofilter.在这种情况下,数组看起来像 criterias=[A,B,C] 当您获得该字符串时,您可以使用自动过滤器。
ThisWorkbook.Worksheets(2).Range("A1").AutoFilter Field:=1, Criteria1:=criterias, Operator:=xlFilterValues
That will filter it so that it shows just all cells which contain A, B or C. You can change Thisworkbook.worksheets(1) to whatever the second workbook is.这将对其进行过滤,以便它仅显示包含 A、B 或 C 的所有单元格。您可以将 Thisworkbook.worksheets(1) 更改为第二个工作簿的任何内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.