我假设您在行和列中有员工和项目,反之亦然。如果您要“取消透视”您的表格,您将能够将其放回透视表并按照您想要的方式进行分组。
在此处查看我的 Table2DB 加载项。
在您的情况下,您可以简单地运行下面的宏并根据您的新工作表创建一个数据透视表
Sub UnPivot()
Dim lLastCol As Long, lLastRow As Long
Dim rgCell As Range, shtOrg As Worksheet, shtDest As Worksheet
Dim lRowDest As Long
'turn off updates to speed up code execution
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
Set shtOrg = ActiveSheet
lLastRow = Cells(Rows.Count, 1).End(xlUp).Row
lLastCol = Cells(48, Columns.Count).End(xlToLeft).Column
Set shtDest = Sheets.Add
lRowDest = 2
shtDest.Cells(1, 1) = "Project"
shtDest.Cells(1, 2) = "Employee"
With shtOrg
For Each rgCell In .Range(.Cells(49, 2), .Cells(lLastRow, lLastCol)).SpecialCells(xlCellTypeConstants)
If rgCell.Value = 1 Then
shtDest.Cells(lRowDest, 1) = .Cells(rgCell.Row, 1)
shtDest.Cells(lRowDest, 2) = .Cells(48, rgCell.Column)
lRowDest = lRowDest + 1
End If
Next rgCell
End With
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
End With
End Sub
要获得没有一起工作的人,请构建如下所示的表格并使用公式: =IF(COUNTIFS(OFFSET($A$49:$A$78,0,MATCH($A2,$48:$48,0)- 1,,),1,OFFSET($A$49:$A$78,0,MATCH(B$1,$48:$48,0)-1,,),1)>0,"Did","没有" ) & “ 一起工作”