-1

源表

 A       B       C       D       E
        AD1     AD2     AD3     AD4
GT1     4010    2000    5000    2000
NT1     1000    2010    5000    2000
PBD1    1000    5000    4000    6000
PBI1    8000    1000    5000    6000

目标表应如下所示,它应动态获取源值

GT1  AD1  4010
GT1  AD2  2000
GT1  AD3  5000
GT1  AD4  2000
NT1  AD1  1000 
NT1  AD2  2010
NT1  AD3  5000
NT1  AD4  2000
PBD1 AD1  1000
PBD1 AD2  5000
PBD1 AD3  4000
PBD1 AD4  6000
PBI1 AD1  8000
PBI1 AD2  1000
PBI1 AD3  5000
PBI1 AD4  6000
4

1 回答 1

0

试试这个代码:

Sub transpose()
Dim cell As Range
Dim targettable As String
Dim runnumber As Integer
runnumber = 1
targettable = "Tabelle2" 'put here the name of the table you need the values put into

Range("B2").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select

For Each cell In Selection
    Sheets(targettable).Range("A" & runnumber).Value = cell.Offset(0, 1 - cell.Column).Value
    Sheets(targettable).Range("B" & runnumber).Value = cell.Offset(1 - cell.Row, 0).Value
    Sheets(targettable).Range("B" & runnumber).Value = cell.Value
    runnumber = runnumber + 1
Next
End Sub

你的最大

于 2013-09-30T15:32:32.667 回答