简体   繁体   English

将按颜色过滤的行复制到新表

[英]Copy Filtered Row by Color to new sheet

I have an Excel spreadsheet that looks something like this: 我有一个看起来像这样的Excel电子表格:

|      | Job1 | Job2 | Job3 | Job4 | Job5 |
| Job1 |      |      |      |      |      |
| Job2 |      |      |      |      |      |
| Job3 |      |      |      |      |      |
| Job4 |      |      |      |      |      |
| Job5 |      |      |      |      |      |

The cells between each row and column are different colors. 每行和每列之间的单元格是不同的颜色。 I need to sort each column by the color orange and then copy the row names to a new sheet. 我需要按橙色对每一列进行排序,然后将行名复制到新表中。

So in the end I would have a sheet like this: 所以最后我会得到一个这样的表:

| Job1 | Job2 |
| Job1 | Job4 |
| Job1 | Job5 |
| Job2 | Job3 |
| Job2 | Job5 |

The idea is if you can do Job1 you should have access to Job2. 这个想法是,如果您可以执行Job1,则应该可以访问Job2。 That is determined by the intersection between column and row from the first sheet. 这由第一张纸上的行与列之间的交点确定。 Try to have a sheet that shows the names instead of the colors. 尝试用一张纸来显示名称而不是颜色。 In all there are 83 jobs so manually doing this would have me copying over 4000. 总共有83个工作,因此手动执行此操作将使我复印4000多个。

Does anyone know how to create a macro to autofilter by color one column at a time and copy the contents of the row in column A1 to a new sheet? 有谁知道如何创建一个宏来一次按颜色对一列进行自动过滤并将A1列中的行内容复制到新工作表中?

I tried to make some sense of the actual data from your description and sample data/results. 我试图从您的描述和样本数据/结果中了解实际数据。 This is what I came up with. 这就是我想出的。

按颜色数据过滤和传输

With that as the active worksheet, I ran this macro. 以此作为活动工作表,我运行了此宏。

Sub organize_by_color()
    Dim rws As Long, c As Long, iCLR As Long, ws As Worksheet, wsT As Worksheet

    Set ws = ActiveSheet
    Set wsT = Worksheets.Add(after:=Sheets(Sheets.Count))

    iCLR = 49407 'Orange e.g. RGB(255, 192, 0)
    wsT.Cells(1, 1).Resize(1, 2) = Array("Job A", "Job B")

    With ws.Cells(1, 1).CurrentRegion
        .AutoFilter
        For c = 2 To .Columns.Count
            .AutoFilter Field:=c, Criteria1:=iCLR, Operator:=xlFilterCellColor
            With .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count)
                rws = Application.Subtotal(103, .Columns(1))
                If CBool(rws) Then
                    .Columns(1).Copy Destination:=wsT.Cells(Rows.Count, 2).End(xlUp).Offset(1, 0)
                    wsT.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Resize(rws, 1) = ws.Cells(1, c).Value
                End If
            End With
            .AutoFilter Field:=c
        Next c
        .AutoFilter
    End With

    Set ws = Nothing
    Set wsT = Nothing

End Sub

This created a new worksheet at the end of the worksheet collection with the following results. 这在工作表集合的末尾创建了一个新的工作表,结果如下。

按颜色结果过滤和传输

To my mind, there isn't much point in having columns E:F in the original data as any relationship noted there would already have been discovered in its reverse through the first three columns but I suppose that data redaction might account for the redundancy. 在我看来,原始数据中的E:F列没有多大意义,因为在前三列中已经发现相反的关系,但是我认为数据编辑可能会导致冗余。 Or I could be completely wrong in my assumptions as the data sample was not noted as to which cells in the matrix actually contained orange color backfill. 否则我的假设可能完全错误,因为数据样本并未指出矩阵中哪些单元格实际包含橙色回填。 Perhaps you will be able to transcribe this for your own purposes. 也许您可以出于自己的目的将其转录。 Post back with questions and specifics if you run into difficulty. 如果遇到困难,请发回问题和详细信息回发。

I ended up making a web interface and converting everything over to a SQL database. 我最终制作了一个Web界面,并将所有内容都转换为SQL数据库。 So the SQL database and logic could do all this instead of trying to put excel on steroids. 因此,SQL数据库和逻辑可以完成所有这些工作,而不是试图在类固醇上表现出色。

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

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