For i = 1 To UBound(CementContractNo())
On Error Resume Next
Row = Application.Match(CementContractNo(i), Range("A:A"), 0)
MsgBox Row
CementStartDate(i) = Cells(Row, ContractStartCol).Value
If Cells(Row, ContractExtCol).Value <> "" Then
CementEndDate(i) = Cells(Row, ContractExtCol).Value
Else
CementEndDate(i) = Cells(Row, ContractEndCol).Value
End If
Next i
我正在运行上面的代码来查找excel表的开始日期和结束日期。但是,当表查找失败时,它将返回错误。在这种情况下,我希望指定一个默认错误值“Missing”或其他要跟进的内容。知道怎么做吗?
答案 0 :(得分:2)
使用这样的结构来精确控制出错时会发生什么
On Error Goto ErrHandling
'Your normal code
'at end of sub
ErrHandling:
'[Your code what happens when you get an error]
Resume Next 'will resume at previous location in code.