我正在尝试使用以下内容将数据从一个工作簿复制并转置到另一个工作簿,但我得到运行时错误1004.任何人都可以帮助解决此问题。它似乎在这部分代码中:
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
我不确定如何解决。
请参阅下面的完整代码:
Windows("ETP2016_scenario_summary (2).xlsx").Activate
ActiveCell.Range("A1:H7").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
ActiveCell.Offset(12, 1).Range("A1:H13").Select
Application.CutCopyMode = False
Selection.Copy
ActiveCell.Offset(0, -1).Range("A1").Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
ActiveWindow.ScrollRow = 19
ActiveWindow.ScrollRow = 26
ActiveCell.Offset(16, 0).Range("A1:H8").Select
Application.CutCopyMode = False
Selection.Copy
ActiveCell.Offset(-4, -1).Range("A1").Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
ActiveWindow.ScrollRow = 40
ActiveCell.Offset(11, 0).Range("A1:H8").Select
Application.CutCopyMode = False
Selection.Copy
ActiveCell.Offset(-3, -1).Range("A1").Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
ActiveWindow.ScrollRow = 44
ActiveCell.Offset(17, 1).Range("A1:H6").Select
Application.CutCopyMode = False
Selection.Copy
ActiveCell.Offset(-5, -1).Range("A1").Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
ActiveWindow.ScrollRow = 62
ActiveCell.Offset(9, 0).Range("A1:H8").Select
Application.CutCopyMode = False
Selection.Copy
ActiveCell.Offset(-2, -1).Range("A1").Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
ActiveWindow.ScrollRow = 68
ActiveCell.Offset(13, 1).Range("A1:H8").Select
Application.CutCopyMode = False
Selection.Copy
ActiveCell.Offset(-1, -1).Range("A1").Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
ActiveWindow.ScrollRow = 79
ActiveCell.Offset(11, 0).Range("A1:H8").Select
Application.CutCopyMode = False
Selection.Copy
ActiveCell.Offset(0, -1).Range("A1").Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
ActiveWindow.ScrollRow = 90
ActiveWindow.ScrollRow = 97
ActiveCell.Offset(11, 0).Range("A1:H16").Select
Application.CutCopyMode = False
Selection.Copy
ActiveCell.Offset(1, -1).Range("A1").Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
ActiveWindow.ScrollRow = 113
ActiveCell.Offset(19, 0).Range("A1:H16").Select
Application.CutCopyMode = False
Selection.Copy
ActiveCell.Offset(-6, -1).Range("A1").Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
End Sub
任何帮助都会非常感激。
答案 0 :(得分:1)
使用转置的第一个粘贴,您没有选择要将其粘贴到的目标范围。
替换你的:
Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True
使用:
' replace Sheet2 with your Sheet Name, Modify Range("A1) to your Range
Worksheets("Sheet2").Range("A1").PasteSpecial Transpose:=True