1004尝试使用设置两个范围对象复制和发送目标时出错

时间:2016-02-24 15:23:46

标签: excel vba excel-vba

大家好,所有人都在接受&#39; 1004&#39;尝试使用复制功能并发送到另一个设定范围时,范围类的复制方法失败。任何想法为什么会这样?下面的代码(注意:我还没有关闭循环。我正在构建设置并遇到此错误。我没有删除循环,因为我只是调试此问题< / strong>):

Sub GetOiData(cmeDataBook As Workbook, oiSheet As Worksheet)
'Loops through OI data sheets and transfers OI data by puts and calls cleanly
Dim dataSheet As Worksheet
Dim startMonthLocation As Range, startRangePutStrike As Range, startRangeCallStrike As Range, monthFutureVolumeFinder As Range
Dim monthConverted As String, callOpt As String, putOpt As String, assetType As String
Dim continue As Boolean

callOpt = " Calls"
putOpt = " Puts"
assetType = oiSheet.Cells(1, 1).Value
continue = True
Set dataSheet = cmeDataBook.Sheets(GetDataSheetDesignation(assetType))
Set startMonthLocation = oiSheet.Cells(2, 2)
dataSheet.Activate

'Iterates through entire Oi data sheet incrementally
Do While continue = True

    'Finds total volume for the month and then sets monthConverted to prepare for oi process
    monthConverted = MonthCode(oiSheet.Cells(2, 2).Value)
    Set monthFutureVolumeFinder = dataSheet.Columns(1).Find(Trim(monthConverted))
    monthFutureVolumeFinder.Offset(0, 4).Copy (startMonthLocation.Offset(1, 0))

Loop

End Sub

1 个答案:

答案 0 :(得分:0)

找到解决方案。似乎有不正确的语法。

<强>更改 monthFutureVolumeFinder.Offset(0,4).Copy (statMonthLocation.Offset(1,0))

monthFutureVolumeFinder.Offset(0,4).Copy Destination:=startMonthLocation.Offset(1,0)

以下完整代码:

Sub GetOiData(cmeDataBook As Workbook, oiSheet As Worksheet)
'Loops through OI data sheets and transfers OI data by puts and calls cleanly

    Dim oiDataSheetInCmeBook As Worksheet
    Dim startMonthLocation As Range, startRangePutStrike As Range, startRangeCallStrike As Range, monthFutureVolumeFinder As Range, monthCallLocationFinder As Range, monthPutLocationFinder As Range
    Dim monthNameConverted As String, callOpt As String, putOpt As String, assetType As String
    Dim continue As Boolean

    callOpt = " Calls"
    putOpt = " Puts"
    assetType = oiSheet.Cells(1, 1).Value
    continue = True
    Set oiDataSheetInCmeBook = cmeDataBook.Sheets(GetDataSheetDesignation(assetType))

    'Sets ranges for initial iteration through specific OI sheet
    Set startMonthLocation = oiSheet.Cells(2, 2)
    Set startRangePutStrike = oiSheet.Cells(5, 1)
    Set startRangeCallStrike = oiSheet.Cells(5, 3)
    dataSheet.Activate

    'Iterates through entire Oi data sheet incrementally
    Do While continue = True

        'Finds total volume for the month and then sets monthConverted to prepare for oi process
        monthNameConverted = MonthCode(oiSheet.Cells(2, 2).Value)
        Set monthFutureVolumeFinder = oiDataSheetInCmeBook.Columns(1).Find(Trim(monthConverted))
        monthFutureVolumeFinder.Offset(0, 4).Copy Destination:=startMonthLocation.Offset(1, 0)

        Set monthPutLocationFinder = oiDataSheetInCmeBook.Columns(1).Find(Trim(monthConverted & putOpt))

    Loop

End Sub