2016-02-24 30 views
0

大家好接收範圍類的「1004」複製方法試圖使用複印功能和發送到另一個設定範圍時失敗。任何想法,爲什麼這可能會發生?下面的代碼(注:我沒有得到關閉循環尚未我是建設的成立,跑進這個錯誤我沒有刪除的循環,因爲我只是在調試這個問題。):1004 Error對象

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 

回答

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 
相關問題