简体   繁体   English

Excel自动筛选,复制选择,粘贴到新表

[英]Excel Autofilter, Copy selection, Paste to new sheet

I have a table with source data in columns Regions!A6:R553 . 我在Regions!A6:R553列中有一个带有源数据的表。

In Regions!A3:R3 , I have formulas that pull specific information out of my data table in Regions!A6:R553 that I want copied to a different sheet. Regions!A3:R3 ,我有一些公式可以将要复制到其他工作表中的特定信息从Regions!A6:R553数据表中Regions!A6:R553

Column A acts as my project name column, while column B holds ID numbers. A列充当我的项目名称列,而B列保留ID号。 In my case, there are multiple ID numbers per project. 就我而言,每个项目有多个ID号。

I am looking for a script to filter and loop through all the unique order numbers in Column B one by one, then copy cells A3:R3 to RegionsSummary!A12:R12 for as many rows as there are unique order numbers (ie, add rows to the table). 我正在寻找一个脚本来过滤和逐列遍历B列中的所有唯一订单号,然后将单元格A3:R3复制到RegionsSummary!A12:R12 ,以获得与唯一订单号一样多的行(即,添加行)到桌子上)。

Here is a screengrab of my data sheet, "Regions": i.stack.imgur.com/aTPuw.png 这是我的数据表“区域”的屏幕截图:i.stack.imgur.com/aTPuw.png

Here is a screengrab of the empty template sheet "RegionsSummary": i.stack.imgur.com/9Ukz5.png 这是空模板“ RegionsSummary”的屏幕截图:i.stack.imgur.com/9Ukz5.png

在此处输入图片说明

Example: Assume there are 5 projects in my data sheet. 示例:假设我的数据表中有5个项目。 I will filter the data using another macro to select Project_1. 我将使用另一个宏选择Project_1来过滤数据。 I would then like a command button to active a macro that will filter to the first order number in Column B, copy Regions!A3:R3 to RegionsSummary!A12:R12 , then filter to the second order number in Project_1, and repeat the process. 然后,我想要一个命令按钮来激活一个宏,该宏将过滤到B列中的第一个订单号,将Regions!A3:R3复制到RegionsSummary!A12:R12 ,然后过滤到Project_1中的第二个订单号,然后重复该过程。 This should go on until all unique ID numbers have been filtered and looped through. 这应该继续进行,直到所有唯一的ID号都已过滤并循环通过为止。

Here is a screengrab of what a final product should look like: i.stack.imgur.com/9Ukz5.png 这是最终产品外观的屏幕截图:i.stack.imgur.com/9Ukz5.png

在此处输入图片说明

Here is a link to the file: Final Output Example 这是文件的链接: 最终输出示例

I would go with an easier solution than a Macro with certain constraints. 与具有某些约束的宏相比,我会选择一种更简单的解决方案。 I am not able to access your sheet, so I will make a sample excel. 我无法访问您的工作表,因此我将提供一个示例。

STEPS: 脚步:

  1. Create a list of unique projects for a dropdown (COPY Regions!A5:A10000 to a new sheet > Data > Remove Duplicates) . 为下拉列表创建唯一项目的列表(将COPY Regions!A5:A10000复制到新工作表>数据>删除重复项)。 Create the dropdown (Data Validation > List > Select Range) using Data Validation in " Example_Result " sheet- C7. 使用“ Example_Result ”表C7中的“数据验证”创建下拉列表(“数据验证”>“列表”>“选择范围”)。

  2. In "Regions", in Col S, put the below formula =S6&"_"&COUNTIF($S$6:S6,S6) Copy this formula down for the entire sheet or as long as you expect the sheet to grow 在“区域”的Col S中,输入以下公式= S6&“ _”&COUNTIF($ S $ 6:S6,S6)将此公式向下复制到整个工作表中,或者只要您希望工作表会增长

  3. In " Example_Result ", insert an index column (1 to 1000, in Col A if you expect each project to have 1000 or less order numbers) from A12 onwards. 在“ Example_Result ”中,从A12开始插入一个索引列(如果希望每个项目的订单号为1000个或更少,则在A列中插入1到1000)。

  4. Along the columns (B onwards) of Row 11 include the names of the variables from Regions (Assessment Project, Highway etc). 在第11行的列(B向前)中,包括区域(评估项目,公路等)中变量的名称。

  5. Insert the below formula in B12 to S1000 (depending on number of variables) of Example_Result : 将以下公式插入到Example_Result的 B12到S1000中(取决于变量数):

=IFERROR(INDEX(Regions!$A$5:$S$10000,MATCH($C$7&"_"&A$12,Regions!$S$5:$S$10000,0),MATCH(B$11,Regions!$A$5:$H$5,0)),"") = IFERROR(INDEX(区域$ A $ 5:!$ S $ 10000,MATCH($ C $ 7 “_” &A $ 12中,区域$ S $ 5:!$ S 10000,0 $),MATCH(B $ 11区域$ A $ 5! :$ H $ 5,0)), “”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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