2
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」などを割り当ててフォローアップしたいと考えています。それを行う方法はありますか?

4

1 に答える 1

3

このような構造を使用して、エラーが発生したときに何が起こるかを正確に制御します

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.

詳細はこちら: http://www.cpearson.com/excel/errorhandling.htm

于 2013-07-13T15:40:47.420 に答える