2015-11-16 153 views
-1

我收到了一個運行時錯誤,在'做的東西'部分中使用以下代碼。附件是文件 - 當我點擊「控制」選項卡上的「檢索記分卡」時,我收到錯誤消息。Excel宏錯誤運行時錯誤

https://www.dropbox.com/s/t8ebv4cl1ms1t2v/010714_NS_Scorecard%20-%20New%20Prototype_V3.xlsm?dl=0

+3

能否請您在這裏發表您的代碼?我不知道是否有太多人(包括我自己)會下載鏈接到互聯網上的某個文件(*尤其是*,我們需要讓宏運行。) – BruceWayne

+0

除了@所提到的固有安全問題之外, BruceWayne,這個問題對於任何未來的目的都是沒用的,沒有發佈代碼註釋來表明哪一行拋出錯誤以及錯誤信息本身。成爲[SO](http://stackoverflow.com/tour)社區的一部分意味着更多地回答自己的問題;這意味着你正在貢獻一個問答庫,以幫助其他人解決同樣的問題。 – Jeeped

+0

正常工作(沒有檢測到錯誤)...案例解決:D –

回答

0

嘗試與

wScorecard.Cells(5, 2).Value = wData.Cells(iSel, 1).Value 
wScorecard.Cells(7, 2).Value = wData.Cells(iSel, 2).Value 
wScorecard.Cells(8, 2).Value = wData.Cells(iSel, 3).Value 
wScorecard.Cells(9, 2).Value = wData.Cells(iSel, 4).Value 

更換' do stuff後,4號線,並檢查是否仍然彈出的錯誤

編輯

請保存工作簿作爲一個新的工作簿,並改變這2個潛艇:

Sub RetrieveScorecard() 

    'This macro will show the overview tab 
    Dim iSel As Integer 
    Dim i As Long 

    Cells(ActiveCell.Row, 1).Select 
    Application.DisplayAlerts = False 
    Application.ScreenUpdating = False 

    If ActiveCell.Value = "" Or ActiveCell.Row < 3 Then MsgBox "No Supplier Selected!", vbOKOnly: Exit Sub 

    If Not MsgBox("You have selected " & ActiveCell.Value & ". Do you want to retrieve this supplier?", vbYesNoCancel + vbInformation, "Retrieve Scorecard") = vbYes Then MsgBox "All action stopped", vbOKOnly: Exit Sub 

    Sheets("Scorecard").Visible = True 

    With Sheets("Data") 
    .Visible = True 
    iCol = .Cells(.Columns(1).Cells.Count, 1).End(xlUp).Row 
    For iSel = 2 To iCol 
     If .Cells(iSel, 1).Value = ActiveCell.Value Then Exit For 
    Next 
    iCol = 1 
    End With 

    ' do stuff 
    For i = 0 To 3 
    Sheets("Scorecard").Cells(Array(5, 7, 8, 9)(i), 2).Value = Sheets("Data").Cells(iSel, i + 1).Value 
    Next 

    'Updates PQScore field to the correct selection 
    With Sheets("Scorecard") 
    For i = 0 To 18 
     iRow = Sheets("Data").Cells(iSel, 5 + i).Value 
     RetrieveValueList (.Cells(Array(14, 18, 19, 20, 21, 22, 26, 27, 28, 32, 36, 37, 38, 39, 40, 41, 45, 46, 47, 48)(i), 3)) 
    Next 
    End With 

    Sheets("Scorecard").Cells(10, 2).Value = Sheets("Data").Cells(iRow, 27) 
    Sheets("Scorecard").Cells(11, 2).Value = Sheets("Data").Cells(iRow, 28) 

    Sheets("Control").Visible = False 
    Sheets("Scorecard").Select 

    Application.DisplayAlerts = True 
    Application.ScreenUpdating = True 

End Sub 

Private Sub RetrieveValueList(rSel As Range) 

    With Sheets("Scorecard") 
    If iRow = 1 Or iRow = 2 Or iRow = 3 Then 
     .Cells(rSel.Row, 2).Value = Range(.Cells(rSel.Row, 2).Validation.Formula1)(4 - iRow) 
    Else 
     .Cells(rSel.Row, 2).Value = "" 
    End If 
    End With 

    Sheets("Data").Select 

End Sub 

然後檢查錯誤...

+0

這似乎工作,但我現在在下面的行中得到一個錯誤: [GTCValue] .Value = Cells(iRow,iCol + 26) [GTCModified_Value] .Value = Cells(iRow,iCol + 27) –

+0

It似乎有'[xyz]'參考的問題... –

+0

@EricMoore我已經編輯了我的答案,請嘗試...看來'ActiveSheet'參考引起了這個麻煩......你可能只需要將'Sheets(「xyz」)。'添加到您的範圍中......在表單之間跳過超過50次並參考「活動」不應該如此運作... –