0
这是我第一次编写实际尝试做某些事情的代码,并且在编写错误处理程序时遇到了一些麻烦。该代码尝试将“tosearch”与范围I1:I10相匹配。如果它找到匹配并且单元格为空,则要求用户输入。VBA Excel错误处理不匹配类型13
很明显,在与循环匹配时存在一个问题,因为循环会在最轻微的不匹配中断。我试图用解决这个“如果ISERROR(等)。”但是我还是不匹配的错误类型13和调试器指向我此行
If IsError(myvalue = Application.Match(tosearch, Range("i1:i10"), 0)) Then
请忽略下面可怕的,广阔的一塌糊涂。它可以正常工作,虽然它还没有任何实际用途,但我希望能够使用它快速识别数组之间的匹配,但也能够控制“正确”匹配是否显示正确的信息。
如果有人有任何答案,您的帮助将非常感激。
Dim myvalue As String
Dim myrng As Long
Dim tosearch As String
Dim myrnglimit As Long
Dim Uchoose As String
Dim animal As Variant
Dim blankchck As String
myrnglimit = 15
For myrng = 2 To myrnglimit
'isblank check
blankchck = Range("c" & myrng).Value
If blankchck = "" Then
'sets tosearch as each cell
tosearch = Range("a" & myrng).Value
'error checker then it matches each cell to the table hardcoded into the code
If IsError(myvalue = Application.Match(tosearch, Range("i1:i10"), 0)) Then
GoTo nextloop:
Else
myvalue = Application.Match(tosearch, Range("i1:i10"), 0)
'fills in the second column with Animal data
animal = Range("j" & myvalue).Value
Range("a" & myrng).Offset(0, 1).Value = animal
'User input for animal
Uchoose = MsgBox("Excel says : " & Range("k" & myvalue).Value & ". So are " & animal & " good?", vbYesNoCancel, "Status")
If Uchoose = vbYes Then
Range("a" & myrng).Offset(0, 2).Value = "Good"
ElseIf Uchoose = vbNo Then
Range("a" & myrng).Offset(0, 2).Value = "Bad"
ElseIf Uchoose = vbCancel Then
GoTo nextloop:
End If
'Select case to identify 1004 mismatch and skip
nextloop:
'Error checker if
End If
'Avoidblank if
End If
Next myrng
我不明白你的问题究竟是什么? – 2014-03-27 11:20:24
你应该使用'If IsError(Application.Match(tosearch,Range(“i1:i10”),0))然后'如果没有错误,将结果写入变量 –
这样做了,我不小心就离开了在错误捕捉器的'myvalue ='中,谢谢。 – user3468246