繁体   English   中英

Excel 宏错误运行时错误

[英]Excel Macro Error Runtime Error

我在“执行操作”部分中使用以下代码收到运行时错误。 附件是文件 - 当我单击“控制”选项卡上的“检索记分卡”时出现错误。

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

尝试在' do stuff with 之后替换 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

然后检查错误...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM