我想要一个宏将我从 Internet 获得的一列数据转换为可用的内容。数据在单元格 a1 到 a540 中,我想转置数据,使单元格 a1 到 a9 的数据变为 a1 到 i1,单元格 a10 到 a18 的数据变为 a2 到 i2,依此类推。
请帮我。
提前谢谢你。
你可以很容易地使用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
从:
到: