Runtime error "6" Overflow.

Hello,

I am currently creating a macro that allows me to delete rows from a column. However, when I try to run it, the error message: "runtime error '6' Overflow." appears.
Here is my program.

Sub Button1()

Dim i As Integer
With ThisWorkbook.Sheets("Sheet1")
For i = .Range("B" & .Rows.Count).End(xlUp).Row To 2 Step -1
If .Range("B" & i).Value = "C00001" Then
.Rows(i).Delete
End If
Next i
End With
End Sub

Can you help me?
Thank you in advance

Configuration: Windows / Chrome 67.0.3396.87

2 answers

  1. Hello,

    Integer: Whole number from -32768 to 32767

    What number is your last line?
    1. My last line is at 1,048,576.
    2. Re,

      you need to declare a long integer
      Long Numeric Integer from -2147483648 to 2147483647.
    3. Re,

      Thank you for this advice, I changed "Dim i As Integer" to "Dim i As Long" but now it shows me a new error message haha; this one: "Runtime Error '13': Type mismatch".
    4. Re,

      My last row is at 1,048,576.
      There's a problem, you have 1,048,576 non-empty cells!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    5. Contributor
      @needhelpohoh, on which line do you have the mistake?