getting an overflow error msg when running macro

kskinne

Well-known Member
Joined
Feb 17, 2002
Messages
1,267
Office Version
  1. 365
Platform
  1. Windows
when i run the following macro:

Code:
Sub test()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
LastRow = Cells.SpecialCells(xlCellTypeLastCell).Row
For i = 9 To LastRow
Cells(i, 4).Value = Cells(i, 5).Value / Cells(i, 3).Value
Next i
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
i get the error message "Run-time error '6': Overflow"

when it hits the line:
Code:
Cells(i, 4).Value = Cells(i, 5).Value / Cells(i, 3).Value

the range of data i am running this macro on is about 20,000 rows of data that is pulled from an access database using a query. the code is erroring out on about row #11,802

anyone know how to avoid this?

thanks,
kevin
 
I guess it's a bit of a semantic point, but in the first one you're doing a calculation and assigning it to a property of an object (the worksheet range's value) and in the second you're trying to assign the outcome of the calculation to a variable. Doesn't seem entirely consistent :D .
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I totally agree, however the underlying value that is being calculated is the same. The method is different, and I guess this is what is causing the differing error messages, but it still doesn't make sense to me. :eek:

Oh, and I voted for Mudface, but Chris Howarth does sound more professional. :)
 
Upvote 0
no luck

hi and thanks for the help, however i'm still getting the error message - none of the rows in either column in question contains a zero value, and it never will due to the type of data i am pulling. could this have something to do with trying to used two different data types in the formula? this was mentioned in a microsoft KB link in one of the previous posts...
 
Upvote 0
I tested the code that was provided on 38,000+ rows of data, and it worked fine. Can you post some sample data using Colo's utility? :confused:
 
Upvote 0
here you go
LD USAGE.xls
ABCDE
8Date/TimeAcctNumberMinutesRateCost
904/23/02712792457214.80.08651.2802
1004/26/027127924572150.08651.2975
1104/20/0288853383241.10.08650.0952
1204/20/0280066823980.90.08650.0779
1304/20/0271282254339.60.08650.8304
1404/20/0271238585310.50.08650.0263
1504/20/0271267328020.50.08650.0433
1604/20/02641439326510.50.08650.9083
1704/20/0264143923931.70.08650.1471
1804/20/0280066823980.50.08650.0433
1904/20/0264143932657.30.08650.6315
2004/20/0264143932650.20.08650.0173
2104/20/0280066823980.60.08650.0519
2204/20/02641439326510.08650.85
2304/20/0288853383241.60.08650.1384
2404/20/0264143932651.40.08650.1211
2504/20/02712822541410.10.08650.8737
usage detail
 
Upvote 0
I'm sorry to have given you bad advice the first time. Try this --

Code:
Sub test()
    Dim i As Long, LastRow as Long
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    LastRow = Cells.SpecialCells(xlCellTypeLastCell).Row
    For i = 9 To LastRow
        On Error Resume Next
        Cells(i, 4) = Cells(i, 5) / Cells(i, 3)
    Next i
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
End Sub
Generates --
Book1
CDEF
9133
10224
11
1230
1340.251
Sheet1
 
Upvote 0
Before you do so, run the macro and when it errors out, enter Debug mode and click on the View- Locals Window. Make a note of what i is and check the appropriate cells and post their values.
 
Upvote 0
Mudface said:
Before you do so, run the macro and when it errors out, enter Debug mode and click on the View- Locals Window. Make a note of what i is and check the appropriate cells and post their values.

I agree. I just tested the code on 30,000 rows of data, and it ran fine with data similar to what your example showed. There must be some values inside your information that are causing this to error.
 
Upvote 0
i found it

when i checked the locals window, it showed the error occurred on row 11803, and sure enough the value of cell C11803 was zero. this numbers pulled from the database for this column are minutes of usage for call records, so there should never be a zero in this column. so i checked the database call record in my usage table, fixed the record that had the zero value, then re-ran my query, and ran the macro. it now works fine. so the culprit really was a zero value. thanks so much to everybody for your help - much appreciated. i can go home at 5:00 now :)

best regards
kevin
 
Upvote 0

Forum statistics

Threads
1,215,514
Messages
6,125,269
Members
449,219
Latest member
daynle

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