基于cell.value excel 2013 vba(for循环)删除行时出错(overFlow)

时间:2016-08-18 08:34:39

标签: excel vba excel-vba loops

我正在检查P列(从第8行开始),如果它包含“Incomplete”,那么我想删除整行,否则什么都不做,但它给了我回运行时错误6 OVERFLOW

这是我的代码:

Private Sub CommandButton3_Click()

Dim i As Integer
Dim Pvalue As String

i = 8

Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False

lastRow = 0
lastRow = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count

MSG1 = MsgBox("are you sure you want to remove the Incomplete rows?", vbYesNo, "Microsoft Excel")

If MSG1 = vbYes Then
    'clearing the body table

    For i = 8 To lastRow
        Pvalue = Range("P" & i).value
        If Pvalue = "Incomplete" Then
            Worksheets("Sheet4").Range("A" & i & ":" + "P" & i).ClearContents
            Worksheets("Sheet4").Range("A" & i & ":" + "P" & i).Interior.ColorIndex = 0
        Else

        End If
    Next
Else

End If

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True
ActiveSheet.DisplayPageBreaks = True

End Sub

1 个答案:

答案 0 :(得分:-1)

谢谢每个人的支持, 实际上在阅读了这个错误(运行时错误6)之后,你为变量使用了错误的数据类型的原因之一, 我用了 昏昏欲睡,而不是 把我变成整数 然后它工作正常。 再次感谢大家。