Code runtime error 6 overflow vba

excel_beginer

New Member
Joined
Dec 28, 2017
Messages
19
I run code then have runtime error 6 overflow vba with this line:

Code:
If ((.Cells(i, 8).Value + .Cells(i, 9).Value) / .Cells(i, 2).Value) < .Cells(3, 15).Value Then

How to fix it
thank a lot./.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
It may be easier for us if you were to provide all your code and explain what your wanting to do.

Like is this line of code inside a With Statement?
 
Upvote 0
Thanks @My Aswer Is This

This's my code
Code:
Sub Check()
Worksheets("check").Range("A2:N5000").Clear
Application.ScreenUpdating = False
Dim i As Long, lastrow As Long, lastrowi As Long
    lastrowi = Sheets("G101").Range("A" & Rows.Count).End(xlUp).Row + 1
    For i = 4 To lastrowi
        lastrow = Sheets("check").Cells(Rows.Count, 2).End(xlUp).Row
        With Sheets("G101")
            If ((.Cells(i, 8).Value + .Cells(i, 9).Value) / .Cells(i, 2).Value) < .Cells(3, 15).Value Then
                .Rows(i).Font.Color = vbRed
                .Rows(i).Copy (Sheets("check").Range("A" & lastrow + 1))
            End If
        End With
    Next i
Application.ScreenUpdating = True
End Sub

Runtiem error and yellow color at line: If ((.Cells(i, 8).Value + .Cells(i, 9).Value) / .Cells(i, 2).Value) < .Cells(3, 15).Value Then
 
Last edited:
Upvote 0
Most likely .Cells(i, 2) on sheet "G101" is empty or zero, meaning the code is trying to divide by zero.
Not quite sure what you would want to happen in that case but try adding something like this.

Rich (BB code):
Sub Check()
Worksheets("check").Range("A2:N5000").Clear
Application.ScreenUpdating = False
Dim i As Long, lastrow As Long, lastrowi As Long
    lastrowi = Sheets("G101").Range("A" & Rows.Count).End(xlUp).Row + 1
    For i = 4 To lastrowi
        lastrow = Sheets("check").Cells(Rows.Count, 2).End(xlUp).Row
        With Sheets("G101")
          If .Cells(i, 2).Value <> 0 Then
            If ((.Cells(i, 8).Value + .Cells(i, 9).Value) / .Cells(i, 2).Value) < .Cells(3, 15).Value Then
                .Rows(i).Font.Color = vbRed
                .Rows(i).Copy (Sheets("check").Range("A" & lastrow + 1))
            End If
          End If
        End With
    Next i
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Thanks @Peter_SSs

I'ver just found the mistake: sheets("G101").Cells(3,15) I format at percent, now I format at general the code work

Thanks all one more time
I'm also glad things seem to be working for you now, but the formatting of cell O3 on G101 as Percentage or General should make no difference to whether the code gave an overflow error or not. :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top