Excel转置 – 基于单元格值

我一直在试图找出一种方法来转置excel中只有某些列成行,以达到我的结果。

由于我需要的输出是文本值,我一直无法使用数据透视表我的目的。 这是附加的图像,显​​示了我有什么,我需要什么。

任何有识之士将不胜感激!

在这里输入图像说明

你没有指定一个excel-vba的技术标签,但是我发现这些是最好的解决scheme,只要你允许某些参数是dynamic的; 例如根据原始数据的大小和性质分配。

 Sub collate() Dim rw As Long, rc As Long, rr As Long, r As Long, c As Long With Sheets("Sheet2") '<-set this worksheet reference properly! rr = Application.Match("item id", .Columns(1), 0) rc = .Cells(rr, Columns.Count).End(xlToLeft).Column + 2 .Cells(rr, rc + 1) = .Cells(rr + 1, 2).Value2 For rw = rr + 1 To .Cells(Rows.Count, 1).End(xlUp).Row If IsError(Application.Match(.Cells(rw, 1).Value2, .Columns(rc), 0)) Then .Cells(Rows.Count, rc).End(xlUp).Offset(1, 0) = .Cells(rw, 1).Value2 End If If IsError(Application.Match(.Cells(rw, 2).Value2, .Cells(rr, rc).Resize(1, 999), 0)) Then .Cells(rr, Columns.Count).End(xlToLeft).Offset(0, 1) = .Cells(rw, 2).Value2 End If r = Application.Match(.Cells(rw, 1).Value2, .Columns(rc), 0) c = Application.Match(.Cells(rw, 2).Value2, .Rows(rr), 0) .Cells(r, c) = .Cells(rw, 3).Value Next rw With .Cells(rr, rc).CurrentRegion With .Resize(.Rows.Count - 1, .Columns.Count).Offset(1, 0) .Cells.Sort Key1:=.Columns(1), Order1:=xlAscending, _ Orientation:=xlTopToBottom, Header:=xlNo End With With .Resize(.Rows.Count, .Columns.Count - 1).Offset(0, 1) .Cells.Sort Key1:=.Rows(1), Order1:=xlAscending, _ Orientation:=xlLeftToRight, Header:=xlNo End With End With End With End Sub 

在对您的数据进行大致的重复运行之后,我想出了这些结果。

整理和排序

请注意,为了演示对结果数据执行的水平sorting过程,我已经使用乱序3005条目专门更改了数据。

请根据您的示例考虑以下解决scheme。

 G3=IF(SUMIFS($C$4:$C$13,$A$4:$A$13,$F4,$B$4:$B$13,G$3)>0,SUMIFS($C$4:$C$13,$A$4:$A$13,$F4,$B$4:$B$13,G$3),"") 

这假设“物品ID”和“扫描事件ID”的每个组合只显示一次。 这使我们可以使用SUMIFS函数加上唯一的相关结果。 请注意,Excel会根据该date的序列号添加它。

如果是防止Excel显示公式返回0和被parsing为实际date。

然后将公式拖到输出表的其余部分。 问候,