VBA overflow error help

pplstuff

Well-known Member
Joined
Mar 9, 2012
Messages
951
I have written the code below. It runs fine until j = 485000 , then I get run-time error overflow. What Am I doing wrong?
Code:
Sub Breakeven()
    Dim i As Integer, j As Long, k As Byte, l As Long
    With ThisWorkbook
    For i = 0 To 9
    j = 445000 + 10000 * i
    Range("c2") = j
        For k = 0 To 9
        l = 2300 + 500 * k
        Range("c3") = l
        Calculate
        Range("c5").GoalSeek Goal:=0, ChangingCell:=Range("c4")
        Range("c4").Select
        Selection.Copy
        Sheets("Sens").Cells(9 + i, 3 + k).Select
        Selection.PasteSpecial Paste:=xlPasteValues
        Next k
    Next i
    End With
End Sub

Thanks for your help!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
You need to be a little more clear with what you are trying to achieve with the Macro and then probably one of the VBA pros could help you out.
 
Upvote 0
Try this:-
When you get your error Click on "Help" to see the Problem and the answer !!!
Code:
j = 445000 + CLng(10000) * i
 
Upvote 0
You just need to declare i as Long rather than Integer. In your code the result of multipling 10000 by 4 was greater than the largest possible integer.
 
Upvote 0

Forum statistics

Threads
1,219,162
Messages
6,146,660
Members
450,706
Latest member
LGVBPP

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