我的源表如下所示
ID Product Amount
22 product1 $10
22 product2 $20
22 product3 $30
33 product2 $4
33 product3 $5
44 product1 $78
44 product4 $90
这是我需要的最终表格:
ID product1 product2 product3 product4
22 $10 $20 $30
33 $4 $5
44 $78 $90
答案1
答案2
有了这样的数据工作表1:
运行简短宏:
Sub TwoDee()
Dim s1 As Worksheet, s2 As Worksheet
Dim N As Long, i As Long, v1 As String, v2 As String, v3 As Long
Dim iRow As Long, iCol As Long
Set s1 = Sheets("Sheet1")
Set s2 = Sheets("Sheet2")
s2.Cells.Clear
N = s1.Cells(Rows.Count, "A").End(xlUp).Row
s1.Range("A2:B" & N).Copy s2.Range("A2")
s2.Range("A:A").RemoveDuplicates Columns:=1, Header:=xlNo
s2.Range("B:B").RemoveDuplicates Columns:=1, Header:=xlNo
s2.Range("B2:B" & N).Copy
s2.Range("B1").PasteSpecial Transpose:=True
s2.Range("B2:B" & N).Clear
For i = 2 To N
v1 = s1.Cells(i, 1).Value
v2 = s1.Cells(i, 2).Value
v3 = s1.Cells(i, 3).Value
iRow = s2.Range("A:A").Find(What:=v1, After:=s2.Range("A1")).Row
iCol = s2.Range("1:1").Find(What:=v2, After:=s2.Range("A1")).Column
s2.Cells(iRow, iCol) = v3
Next i
End Sub
将在工作表2:
答案3
http://www.excel-easy.com/examples/transpose.html
在 Google 上首次搜索到“excel 2010 transpose”。
基本上,您选择要转置的所有数据(包括任何列或行标题),按 Ctrl + C 复制它,右键单击要粘贴它的左上角单元格并选择性粘贴选中转置框并点击确定,您就完成了。