Runtime error "6" Overflow.

needhelp -  
yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   -
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. f894009 Posted messages 17417 Registration date   Status Member Last intervention   1 717
     
    Hello,

    Integer: Whole number from -32768 to 32767

    What number is your last line?
    0
    1. needhelp
       
      My last line is at 1,048,576.
      0
    2. f894009 Posted messages 17417 Registration date   Status Member Last intervention   1 717
       
      Re,

      you need to declare a long integer
      Long Numeric Integer from -2147483648 to 2147483647.
      0
    3. needhelp
       
      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".
      0
      1. yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588 > needhelp
         
        ohoh, on which line do you have the mistake?
        0
    4. f894009 Posted messages 17417 Registration date   Status Member Last intervention   1 717
       
      Re,

      My last row is at 1,048,576.
      There's a problem, you have 1,048,576 non-empty cells!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      0