繁体   English   中英

VBA Excel错误处理不匹配类型13

[英]VBA Excel Error Handling Mismatch type 13

这是我第一次编写实际上尝试执行某项操作的代码,而在编写错误处理程序时遇到了一些麻烦。 该代码尝试将“ tosearch”匹配到I1:I10范围。 如果找到匹配项,并且该单元格为空白,则要求用户输入。

显然,与循环匹配存在问题,因为循环将以不匹配的丝毫嗅觉中断。 我试图用'If iserror(etc。)'解决这个问题,但是我仍然遇到错误类型为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

我认为可能是由于您范围内的数据类型与字符串变量toSearch之间存在差异而引起的。 我建议按以下方式设置toSearch:

Dim tosearch As Variant

以下链接描述了与我在此处定义的问题类似的问题和相似的解决方案。

http://www.excelforum.com/excel-programming-vba-macros/358571-application-match.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM