我是VBA的新手。Excel VBA:将数据从一个工作簿中的列转移到另一个工作簿中的行
将数据从一个工作簿中的列转移到另一个工作簿,因为行正在抛出错误。试图从这个论坛和其他地方提出建议,但没有成功。
任何帮助将高度赞赏 -
**
错误运行时错误1004 - Range类> PasteSpecial方法失败
**
代码 -
*
Sub Button1_Click()
Dim MyFile As String
Dim erow
Dim FilePath As String
FilePath = "C:\trial\"
MyFile = Dir(FilePath)
Do While Len(MyFile) > 0
If MyFile = "here.xlsm" Then
Exit Sub
End If
'Opening data.xls to pull data from one column with 2 values (E6 and E7)
Workbooks.Open (FilePath & MyFile), Editable:=True
Dim SourceRange As Range
Set SourceRange = ActiveSheet.Range("E6:E7")
SourceRange.Copy
ActiveWorkbook.Close SaveChanges:=True
'Back to calling file - here.xlsm and pasting both values in single row (for e.g. A2 and B2)
erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Dim targetRange As Range
Set targetRange = ActiveSheet.Cells(erow, 1)
targetRange.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
MyFile = Dir
Loop
End Sub
*
那么是什么错误? – Sorceri
抱歉错过了 - 错误在targetRange.PasteSpecial行。错误 - > Range类的PasteSpecial方法失败 – Anand
以及您收到的实际错误消息是什么? – Sorceri