• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Run Time Error 9 "Overflow"

Dokat

Member
Hi,

I am getting run time error 9 "overflow" error when i ran the below code. Line 2 is highlighted in yellow. not sure whats causing this. Anyone come across the same issue and have a solve for it? Thanks

Code:
Sub MathLWBRAND()

Dim i As Variant
Dim condition As Range

For i = 30 To 57

Sheets("HDD").Cells(i, 9) = Sheets("HDD").Cells(i, 7) - Sheets("HDD").Cells(i, 8)
Sheets("HDD").Cells(i, 10) = Sheets("HDD").Cells(i, 7) / Sheets("HDD").Cells(i, 8) - 1
Sheets("HDD").Cells(i, 11) = Sheets("HDD").Cells(i, 7) / Sheets("HDD").Range("G30") * 100
Sheets("HDD").Cells(i, 12) = Sheets("HDD").Cells(i, 8) / Sheets("HDD").Range("H30") * 100
Sheets("HDD").Cells(i, 13) = Sheets("HDD").Cells(i, 11) - Sheets("HDD").Cells(i, 12)
Next i

End Sub
 
Hi ,

Try this :
Code:
Sub MathLWBRAND()
    Dim i As Long
    Dim condition As Range
   
    Application.ScreenUpdating = False

    With Sheets("HDD")
        For i = 30 To 57
            .Cells(i, 9) = .Cells(i, 7) - .Cells(i, 8)

            If .Cells(i, 8) <> 0 Then
                .Cells(i, 10) = .Cells(i, 7) / .Cells(i, 8) - 1
            End If
         
            If .Range("G30") <> 0 Then
                .Cells(i, 11) = .Cells(i, 7) / .Range("G30") * 100
            End If
       
            If .Range("H30") <> 0 Then
                .Cells(i, 12) = .Cells(i, 8) / .Range("H30") * 100
            End If
       
            .Cells(i, 13) = .Cells(i, 11) - .Cells(i, 12)
        Next i
    End With
   
    Application.ScreenUpdating = True
End Sub
Narayan
 
I was testing the code now coming across Run Time Error 11 Division by Zero error how can i prevent this error message? Cells highlighted bold is the line its giving error.

Code:
Sub MathL4WBRAND()
    Dim i As Long
    Dim condition As Range
   
    Application.ScreenUpdating = False

    With Sheets("HDD")
        For i = 30 To 57
            .Cells(i, 16) = .Cells(i, 14) - .Cells(i, 15)

            If .Cells(i, 8) <> 0 Then
                .Cells(i, 17) = .Cells(i, 14) / .Cells(i, 15) - 1
            End If
         
            If .Range("G30") <> 0 Then
                .Cells(i, 18) = .Cells(i, 14) / .Range("n30") * 100
            End If
       
            If .Range("H30") <> 0 Then
                .Cells(i, 19) = .Cells(i, 15) / .Range("o30") * 100
            End If
       
            .Cells(i, 20) = .Cells(i, 18) - .Cells(i, 19)
        Next i
    End With
   
    Application.ScreenUpdating = True
End Sub
Thanks
 
Hi ,

Please change your statements to suit the different references that you are using.

When your code is :

If .Cells(i, 8) <> 0 Then
.Cells(i, 17) = .Cells(i, 14) / .Cells(i, 15) - 1
EndIf

If .Range("G30") <> 0 Then
.Cells(i, 18) = .Cells(i, 14) / .Range("n30") * 100
EndIf

If .Range("H30") <> 0 Then
.Cells(i, 19) = .Cells(i, 15) / .Range("o30") * 100
EndIf

The colored portions have to be identical to one another i.e. the portions colored red have to be identical to each other ; the portions colored magenta have to be identical to each other , and the portions colored brown have to be identical to each other.

Narayan
 
Back
Top