将excel数据从1列转换为多行

时间:2013-11-07 13:32:33

标签: excel excel-vba vba

我想要一个宏将我从互联网上获得的一列数据转换为可用内容。 数据在单元格a1到a540中,我想转置这样的数据 从单元格a1到a9的数据变为a1到i1, 从单元格a10到a18的数据变为a2到i2,依此类推。

请帮帮我。

提前感谢你。

1 个答案:

答案 0 :(得分:0)

您可以使用PasteSpecial - >轻松完成此操作Transpose

如果要自动化它,请记录一个宏并查看它生成的代码


此外,这里有一些VBA可能会让你走上正轨......

虽然

有点破解和削减
Public Sub TransposePaste()


'Value we want to step by
Dim stepVal As Long
stepVal = 9


'Declare start row variable (-1)
Dim row As Long
row = 0

'Declare the column the data is coming from
Dim col As Long
col = 1

'Declare and set worksheet
Dim ws As Worksheet
Set ws = Sheet1

'end row of the data
Dim endRow As Long


endRow = ws.Cells(ws.Rows.Count, col).End(xlUp).row

    'cycle to end of data end of data...
    For i = 1 To endRow Step stepVal

    'increment row each time
    row = row + 1

        'cycle through the columns outputting the data
        For j = 1 To stepVal

        Sheet1.Cells(row, j).Value = Sheet1.Cells(i + j - 1, col).Value

        Next j
    Next i

End Sub

自:

From_1

致:

To_1