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

将excel数据从一列转换为多行,excel,vba,Excel,Vba,我想要一个宏来将我从互联网上获得的一列数据转换成可用的内容。 数据在单元格a1到a540中,我想转换数据,以便 从单元格a1到a9的数据变为a1到i1, 从单元格a10到a18的数据变为a2到i2,依此类推 请帮帮我 提前感谢。您可以使用PasteSpecial->转置 如果您想自动化它,那么记录一个宏并检查它生成的代码 此外,这里有一点VBA,它可能会让您走上正确的道路 不过这有点老套 Public Sub TransposePaste() 'Value we want to step

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

请帮帮我


提前感谢。

您可以使用
PasteSpecial
->
转置

如果您想自动化它,那么记录一个宏并检查它生成的代码


此外,这里有一点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
发件人:

致:


您有什么版本的Excel?