簡體   English   中英

獲取“運行錯誤時間'13':單元格中“DIV/0”值的類型不匹配

[英]Getting “Run error time '13': Type Mismatch on ”DIV/0" value in cell

我收到Run error time '13': Type Mismatch on "#DIV/0 value in cell 我試圖用我的代碼解決但沒有達到這一點但 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, button1, 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, 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
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)
            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.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM