我在' do stuff'中使用以下代码收到运行时错误。部分。附件是文件 - 当我点击"检索记分卡"我收到错误。在'控制'标签
https://www.dropbox.com/s/t8ebv4cl1ms1t2v/010714_NS_Scorecard%20-%20New%20Prototype_V3.xlsm?dl=0
答案 0 :(得分:0)
尝试使用
替换' do stuff
之后的4行
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
并检查是否仍然会弹出错误
修改强>
请将您的工作簿另存为新工作簿并更改以下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
然后检查错误......