gpt4 book ai didi

excel - 如何设置默认错误值?

转载 作者:行者123 更新时间:2023-12-04 04:49:32 25 4
gpt4 key购买 nike

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”或其他东西来跟进。知道怎么做吗?

最佳答案

使用这样的结构来精确控制出现错误时会发生什么

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

关于excel - 如何设置默认错误值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17626549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com