简体   繁体   English

根据单元格值将多张纸中的行复制到一张纸中

[英]Copy rows from multiple sheets into one sheet based on a cell value

I want to copy rows from multiple sheets into one combined sheet based on a cell valve. 我想将多个工作表中的行复制到一个基于单元阀的组合工作表中。

Details: 细节:
I have multiple project numbers that are tabs (2016-010-082, 2016-010-086, 2016-060-015... etc). 我有多个标签的项目编号(2016-010-082、2016-010-086、2016-060-015 ...等)。 In column E on each of these sheets I have a dropdown box where you can pick "yes" or "no" based on if this task is completed or not. 在每张工作表的E列中,我都有一个下拉框,您可以根据此任务是否完成来选择“是”或“否”。 I would like where all the tasks that are "no", the row will copy over into a single sheet so I can see all the tasks for all the projects that are not yet completed. 我想将所有“否”的任务复制到一个工作表中,以便查看所有尚未完成的项目的所有任务。

When the "no" is changed to a "yes" on the specific project tab, I would like the row to be removed from the compiled sheet as well. 当在特定项目选项卡上将“否”更改为“是”时,我也希望将该行也从已编译的工作表中删除。

I would also like cells D2 and D3 from each show up in rows A and B of the compiled sheet as that is standard information for each tab that I will need to see on the compiled sheet so I know which project number it is and the project name. 我还希望每个单元格的D2和D3都显示在已编译工作表的A和B行中,因为这是我需要在已编译工作表上看到的每个选项卡的标准信息,所以我知道它是哪个项目号以及哪个项目名称。

Sample image. 样本图片。 样本图片

This is what I thought would work for one sheet. 我认为这将适用于一张纸。

Sub Test()
    For Each Cell In Sheets(1).Range("E:E")
        If Cell.Value = "NO" Then
            matchRow = Cell.Row
            Rows(matchRow & ":" & matchRow).Select
            Selection.Copy
            Sheets("Sheet2").Select
            ActiveSheet.Rows(matchRow).Select
            ActiveSheet.Paste
            Sheets("Sheet1").Select
        End If
    Next
End Sub

For the first part, where you want a list of just those facilities with "No", you can use this array formula (enter with CTRL+SHIFT+ENTER ): 对于第一部分,您只需要带有“否”的那些设施的列表,则可以使用此数组公式(输入CTRL + SHIFT + ENTER ):

=INDEX(B$2:B$4,SMALL(IF($D$2:$D$4="Yes",ROW(B$2:B$4)-ROW(B$2)+1),ROWS(B$2:B2)))

Assuming your data is laid out like this: 假设您的数据是这样布置的: 在此处输入图片说明

Then, wrap IfError([formula],"") around that to hide the #NUM errors. 然后,将IfError([formula],"")包裹起来以隐藏#NUM错误。 As you change "No" in "Completed" to "Yes", the list on the right will update. 当您将“已完成”中的“否”更改为“是”时,右侧的列表将更新。

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

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