Excel:运行时错误“13”types在删除行执行过程中不匹配

什么会导致这条线

If Cells(i, 3) = "" Or VBA.Left(Cells(i, 3), 5) = "BIGA-" Or VBA.Left(Cells(i, 3), 5) = "BRNG-" Or VBA.Left(Cells(i, 3), 5) = "ENER-" Or VBA.Left(Cells(i, 3), 5) = "EURE-" Or VBA.Left(Cells(i, 3), 5) = "STRE-" Then Rows(i).Delete

在下面的macros返回一个运行时错误'13'types不匹配后,第一个单元格logging被发现并删除?

 Option Explicit Sub deletedExceptions_row() Dim i As Long For i = Cells.SpecialCells(xlCellTypeLastCell).Row To 1 Step -1 If Cells(i, 3) = "" Or VBA.Left(Cells(i, 3), 5) = "BIGA-" Or VBA.Left(Cells(i, 3), 5) = "BRNG-" Or VBA.Left(Cells(i, 3), 5) = "ENER-" Or VBA.Left(Cells(i, 3), 5) = "EURE-" Or VBA.Left(Cells(i, 3), 5) = "STRE-" Then Rows(i).Delete Next i End Sub 

尝试这个

 Option Explicit Sub deletedExceptions_row() Dim i As Long Dim ws As Worksheet On Error GoTo whoa Set ws = Sheets("Sheet1") With ws For i = .Cells.SpecialCells(xlCellTypeLastCell).Row To 1 Step -1 If .Cells(i, 3) = "" Or _ VBA.Left(.Cells(i, 3), 5) = "BIGA-" Or _ VBA.Left(.Cells(i, 3), 5) = "BRNG-" Or _ VBA.Left(.Cells(i, 3), 5) = "ENER-" Or _ VBA.Left(.Cells(i, 3), 5) = "EURE-" Or _ VBA.Left(.Cells(i, 3), 5) = "STRE-" Then .Rows(i).Delete End If Next i End With Exit Sub whoa: MsgBox "Value of i is " & i, vbInformation, Err.Description End Sub 

现在它给出了一个错误? 如果是的话, i的价值是多less。 如果i的值是17,那么检查单元格C17。 我确信在那个单元里有一个公式给出了一个错误。 例如#DIV/0! 或任何其他错误。 只有在这种情况下它会给出一个type mismatch error

快照

在这里输入图像说明