如何解决获取“运行错误时间‘13’:单元格中“DIV/0”值的类型不匹配
我在单元格中得到 Run error time '13': Type Mismatch on "#DIV/0
值,我试图用我的代码解决这个问题,但没有达到这一点,但是 vba 跳过了实现第一个 if 条件(卸载用户表单并退出这个条件)并导致这个一次又一次的错误。
调试代码中突出显示的行是 If ws.Cells(iRow,32) = True Then
。
当单元格中的值为 #DIV/0
时,出现此错误是正常的,但我尝试事先检查并在发生这种情况时退出该条件。
代码如下:
If ws.Cells(45,7) = 1 Then
Dim msg1,button1,title1,response1
msg1 = "Are you sure you don't want to check any of the presented questions? In this case,Contractual factors category will be removed from the evaluation process and the weights will be reallocated."
button1 = vbYesNo + vbDefaultButton2
title1 = "Confirmation Notice"
response1 = MsgBox(msg1,title1)
If response1 = vbYes Then
If ws.Cells(53,6).Value = 1 Then
MsgBox "No single factor was selected. Thus,there are no results to be evaluated."
Unload Me
Call clear_data
Dashboard.Show
Else
iRow2 = 2
For iRow = 2 To 7
**If ws.Cells(iRow,32) = True Then**
ws.Cells(iRow2,38).Value = ws.Cells(iRow,27)
ws.Cells(iRow2,39).Value = ws.Cells(iRow,31)
iRow2 = iRow2 + 1
End If
Next iRow
Unload Me
conf.Show
End If
Else
Exit Sub
End If
Else
iRow2 = 45
For iRow = 45 To 51
If ws.Cells(iRow,6) = True Then
ws.Cells(iRow2,9).Value = ws.Cells(iRow,3)
ws.Cells(iRow2,10).Value = ws.Cells(iRow,4)
iRow2 = iRow2 + 1
End If
Next iRow
End If
If ws.Cells(8,32).Text = "#DIV/0!" Then
Unload Me
Dashboard.Show
ElseIf ws.Cells(8,32) = 1 Then
iRow2 = 2
For iRow = 2 To 7
If ws.Cells(iRow,32) = True Then
ws.Cells(iRow2,27)
ws.Cells(iRow2,31)
iRow2 = iRow2 + 1
End If
Next iRow
Unload Me
conf.Show
Else
iRow2 = 2
For iRow = 2 To 7
If ws.Cells(iRow,31)
ws.Cells(iRow2,41).Value = ws.Cells(iRow,31)
iRow2 = iRow2 + 1
End If
Next iRow
Unload Me
CPIGauge.Show
End If
如果您对此错误有任何帮助,我将不胜感激。
解决方法
尽量不要检查错误:
If ws.Cells(8,32).Text = "#DIV/0!" Then
尽量避免:
If ws.Cells(1,3).Value = 0 Then 'Do something to handle the zero before the division.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。