2014-03-18 65 views
1

發生故障的線路,通過‘設置X =’方法「對象範圍」 _Worksheet」失敗 - 但如果我叫子從另一個子

這可能是大的線索開始:當我運行這個代碼作爲一個單獨的子,它運行良好。我只從的另一個子中調用此子時出錯。爲什麼會這樣呢?

Option Explicit 

Sub EIRPChartUpdate() 
'update EIRP Chart 
Application.ScreenUpdating = False 

    Dim x As Range, y1 As Range, y2 As Range, y3 As Range, y4 As Range 
    Dim points As Long 

    Set EIRPChart = Sheets("EIRP Chart") 
    Set EIRPSummary = Sheets("EIRP Summary") 

    'get last row of EIRP Summary 
    lastEIRPSummaryRow = EIRPSummary.Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row 

    'count the number of data points 
    points = lastEIRPSummaryRow - [ESDataRow1].Row + 1 

'set independent and dependent data ranges 
With EIRPSummary 
    Set x = .Range(Cells([ESDataRow1].Row, [ESCaseNum].Column), Cells(lastEIRPSummaryRow, [ESCaseNum].Column)) 
    Set y1 = .Range(Cells([ESDataRow1].Row, [ESPriSpec100].Column), Cells(lastEIRPSummaryRow, [ESPriSpec100].Column)) 
    Set y2 = .Range(Cells([ESDataRow1].Row, [ESPriPred100].Column), Cells(lastEIRPSummaryRow, [ESPriPred100].Column)) 
    Set y3 = .Range(Cells([ESDataRow1].Row, [ESPriPred95].Column), Cells(lastEIRPSummaryRow, [ESPriPred95].Column)) 
    Set y4 = .Range(Cells([ESDataRow1].Row, [ESPriPred90].Column), Cells(lastEIRPSummaryRow, [ESPriPred90].Column)) 
End With 

'more code ... 
+0

嘗試之前'單元格添加時期'.'也'像這樣:'Set x = .Range(.Cells([ESDataRow1] .Row,[ESCaseNum] .Column),.Cells(lastEIRPSummaryRow,[ESCaseNum] .Column))' –

+0

@simoco that worked。你已經做到了,我非常感激。 – jmaz

回答

1

由於從評論跟進,

Cells應該是完全合格的,即您應該指定表到細胞屬於:

With EIRPSummary 
    Set x = .Range(.Cells([ESDataRow1].Row, [ESCaseNum].Column), .Cells(lastEIRPSummaryRow, [ESCaseNum].Column)) 
    Set y1 = .Range(.Cells([ESDataRow1].Row, [ESPriSpec100].Column), .Cells(lastEIRPSummaryRow, [ESPriSpec100].Column)) 
    Set y2 = .Range(.Cells([ESDataRow1].Row, [ESPriPred100].Column), .Cells(lastEIRPSummaryRow, [ESPriPred100].Column)) 
    Set y3 = .Range(.Cells([ESDataRow1].Row, [ESPriPred95].Column), .Cells(lastEIRPSummaryRow, [ESPriPred95].Column)) 
    Set y4 = .Range(.Cells([ESDataRow1].Row, [ESPriPred90].Column), .Cells(lastEIRPSummaryRow, [ESPriPred90].Column)) 
End With 
+1

我認爲通過指定範圍所屬的工作表,其中的單元格也將被指定到同一工作表,但我現在看到情況並非如此。再次感謝。 – jmaz

相關問題