VBA将数据从一个工作簿传输到另一个工作簿

时间:2016-10-19 09:40:00

标签: excel-vba vba excel

我尝试编写以下内容以将数据从一个工作簿传输到另一个工作簿,但是,它会获得超出脚本范围的错误9。我检查了两次,找不到任何错误。你能帮忙检查一下我是否遗漏了什么或者出了什么问题?非常感谢。

Private Sub Transfer_Click()

Application.ScreenUpdating = False
Sheets("List").Select
v = Range("A2").End(xlDown).Row
Dim a()
Dim b()
ReDim a(v - 1)
ReDim b(v - 1)
Sheets("Yahoo").Select
For i = 0 To v - 1 
a(i) = Cells(i + 7, 4) 
b(i) = Cells(i + 7, 5)
Next

ChDir "C:\Users\Desktop\Data Analysis"
Workbooks.Open Filename:="C:\Users\Desktop\Data Analysis\Data.xlsx"

Sheets("List").Select
For i = 2 To Range("A1").End(xlDown).Row 
Sheets("List").Select 
k = Cells(i, 1) 
If k = "" Then Exit For 
Sheets(k).Select 
h = Range("B8").End(xlDown).Row 
Cells(h + 1, "B") = a(i - 2) 
Cells(h + 1, "F") = b(i - 2)
Next

Windows("Data.xlsm").Activate
Sheets("Yahoo").Select
Application.CutCopyMode = False
Workbooks("Data.xlsx").Save
Workbooks("Data.xlsx").Close
Application.ScreenUpdating = True
MsgBox "Successfully transferred!", vb0XOnly, "Notice"


End Sub

0 个答案:

没有答案