我有一个录制的宏,我正在尝试使用循环,以便我可以一次转置多个行和列。我的想法是我有10000行,其中包含1000列电子邮件。我想使用宏将我的行数据转换为使用do while或loop的列。我记录了宏,但它只适用于一行和一列。代码就在那里。
Sheets("Mastersheet").Select
Range("J2:XFD2").Select
Selection.Copy
Sheets("Sheet2").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
答案 0 :(得分:1)
如果您至少尝试搜索答案和信息,则可以更快地解决问题。
Excel VBA - Range.Copy transpose paste
代码:
Option Explicit
Sub test()
Dim master_sheet As Worksheet
Set master_sheet = ThisWorkbook.Sheets("Mastersheet")
Dim output_sheet As Worksheet
Set output_sheet = ThisWorkbook.Sheets.Add
Dim start_row As Long
start_row = 2
Dim last_row As Long
With master_sheet
last_row = .Cells(.Rows.Count, "J").End(xlUp).Row
.Range("J" & start_row & ":XFD" & last_row).Copy
End With
With output_sheet
.Range("A1").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
End With
End Sub
答案 1 :(得分:1)
试试这个:
Sub Macro9()
t = 2
Do Until t = 10000
Sheets("Mastersheet").Range("J" & t & ":XFD" & t).Copy
Sheets("Sheet2").Select
Sheets("Sheet2").Cells(1, t).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
t = t + 1
Loop
End Sub