如何将范围内的每一行复制并转置粘贴到新工作表上?

时间:2019-07-17 02:06:03

标签: excel vba

我有一个工作表,上面有不同的数据。我要复制,转置将指定范围内的每一行粘贴到每一行的单独工作表上。我对此很陌生,因为我对此很陌生。

我不太明白从哪里开始。

Sub LoopRow()

Dim rng As Range
Dim row As Range
Dim cell As Range

Set rng = Range("A6:AI57")

For Each row In rng.Rows


End Sub

2 个答案:

答案 0 :(得分:0)

使用此代码:

您需要做的就是更改工作表名称。我们正在遍历指定范围,并使用Transpose将每一行复制粘贴到另一个工作表列上。

Sub LoopRow()

Dim rng As Range
Dim row As Range
Dim cel As Range
Dim i As Integer

Set rng = Worksheets("Name of sheet where data is").Range("A6:AI57")

i = 1
For Each row In rng.Rows

    row.Copy
    Worksheets("Name where you want your data to go").Cells(1, i).PasteSpecial Transpose:=True
    i = i + 1

Next

End Sub

它将粘贴第一个单元格中的数据。您可以通过将cells(2,i)更改为第二以此类推。

答案 1 :(得分:0)

尝试此宏

   Option Explicit
Sub TranPose_Range()
Dim rng As Range

'Source_sheet====>> name of sheet where the data is
'Target_sheet====>> name of sheet where you want your data to go
   Set rng = Sheets("Source_sheet").Range("A6").CurrentRegion
   rng.Copy
   Sheets("Target_sheet").Cells(1, 1).PasteSpecial , Transpose:=True

End Sub