简体   繁体   中英

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.

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. 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.

criterias = Split(ThisWorkbook.Worksheets(1).Cells(2, 1).Value, ";")

It splits the string in sheet 1 cell A2 into an array, it cuts at ";"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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM