VBA运行时错误'1004'

时间:2016-06-22 21:38:39

标签: vba

VBA新手,我在尝试将数据从一个工作簿复制到第二个工作簿时遇到了问题。错误由***突出显示。运行时错误'1004'我搜索了您的网站,但未能找到答案。在此先感谢您的帮助。

Option Explicit
    Sub CopyColumnTest()

Const FILE1 As String = "c:\users\john\documents\cvi - excel `enter code here`files\project    - Cash Drawer Report\New Folder\PreFlashSales.xls"
Const FILE2 As String = "c:\users\john\documents\cvi - excel files\project - Cash Drawer Report\New Folder\2016 Flash Sales-JFP.xls"
Const Sheet1 As String = "Sheet1"
Const Sheet2 As String = "Actual"
Dim Col As Integer
Dim Col1 As Integer
Dim Col2 As Integer
Dim RowNum As Integer
Dim RowNum1 As Integer
Dim RowNum2 As Integer
Dim LastRow1 As Integer
Dim LastRow2 As Integer
Dim wb1 As Workbook, wb2 As Workbook
Dim i As Integer
Dim wksSource As Worksheet
Dim wksDest As Worksheet

'Set wksSource = ActiveWorkbook.Sheets(Sheet1)
'Set wksDest = ActiveWorkbook.Sheets(Sheet2)

i = 1
Col = 5
Col1 = 2
Col2 = 24

RowNum = 2
RowNum1 = 129


If wb1 Is Nothing Then Set wb1 = Workbooks.Open(FILE1)
Set wksSource = ActiveWorkbook.Sheets(Sheet1)

If wb2 Is Nothing Then Set wb2 = Workbooks.Open(FILE2)
Set wksDest = ActiveWorkbook.Sheets(Sheet2)

LastRow1 = wb1.Sheets(Sheet1).Cells(Rows.Count, "B").End(xlUp).row 'Last Row of Data in PreFlashSales Workbook

LastRow2 = wb2.Sheets(Sheet2).Cells(Rows.Count, "E").End(xlUp).row + 1 'Last Row of Data Previously Added in 2016 FlashSales-JFP

    With wb1.Sheets(Sheet1)

        For i = 1 To LastRow1
       *** wb2.Sheets(Sheet2).Range(Col & RowNum1, Col2 & RowNum1).Value = wb1.Sheets(Sheet1).Range(Col1 & RowNum, (Col1 + 19) & RowNum).Value***
            Col = Col + 1
            Col1 = Col1 + 1
            RowNum = RowNum + 1
            RowNum1 = RowNum1 + 1
        Next i
    End With
End Sub

0 个答案:

没有答案