gpt4 book ai didi

vba - 错误时为变量赋值

转载 作者:行者123 更新时间:2023-12-03 07:46:38 25 4
gpt4 key购买 nike

我想要做的是,如果出现错误,某些值会被重置。就像是:

Dim r As Integer
Dim feeder As String
Dim origen As String

On Error GoTo errhandler:
For j=1 to 100
r = Evaluate("=MATCH(1, (C:C=""" & feeder & """) * (D:D=""" & origen & """),0)")
Next j

Exit Sub

errhandler:
r = 0
End Sub

但是我如何强制它回到 For如果有错误?

最佳答案

您可以使用 IsError 来设置 r 的值,而不是 ErrHanlding关于错误:

Sub t1()
Dim feeder As String
Dim origen As String
For j = 1 To 100
Dim r As Variant
If IsError(Evaluate("=MATCH(1, (C:C=""" & feeder & """) * (D:D=""" & origen & """),0)")) Then
r = 0
Else
r = Evaluate("=MATCH(1, (C:C=""" & feeder & """) * (D:D=""" & origen & """),0)")
End If
Debug.Print r ' Just for you to check
Next

End Sub

关于vba - 错误时为变量赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37471571/

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