elifillmore
New Member
- Joined
- Mar 15, 2011
- Messages
- 2
While writing some more complex code I encountered a run-time error that has me stumped. I isolated the code to just a few lines and then self contained the code. I've included three different ways of coding the same formula but 2 of the example generate error and 1 works just fine. My question is why? Does anyone know the logic behind the what is generating the overflow errors? Has anyone seen examples like this before?
I tested this on 2 different computers and got the same results.
1) Excel 2003 w XP SP3 (3G/4GB RAM)
2) Excel 2010 w XP SP3 (3G/2GB RAM)
Thanks in advance!
'EXAMPLE 1: (This one works just fine = Msgbox with "900000")
Sub Example1()
Dim N As Long, L As Long
N = 15
L = N * 1000 * 60
MsgBox L
End Sub
'EXAMPLE 2: (Results in a Run Time Error 6: Overflow error. I replaced the N in L with 15 as opposed to the variable)
Sub Example2()
Dim N As Long, L As Long
N = 15
L = 15 * 1000 * 60
MsgBox L
End Sub
'EXAMPLE 3 (Results in a Run Time Error 6: Overflow error. Moved the N variable from the first to the end of the calculation)
Sub Example3()
Dim N As Long, L As Long
N = 15
L = 1000 * 60 * N
MsgBox L
End Sub
I tested this on 2 different computers and got the same results.
1) Excel 2003 w XP SP3 (3G/4GB RAM)
2) Excel 2010 w XP SP3 (3G/2GB RAM)
Thanks in advance!
'EXAMPLE 1: (This one works just fine = Msgbox with "900000")
Sub Example1()
Dim N As Long, L As Long
N = 15
L = N * 1000 * 60
MsgBox L
End Sub
'EXAMPLE 2: (Results in a Run Time Error 6: Overflow error. I replaced the N in L with 15 as opposed to the variable)
Sub Example2()
Dim N As Long, L As Long
N = 15
L = 15 * 1000 * 60
MsgBox L
End Sub
'EXAMPLE 3 (Results in a Run Time Error 6: Overflow error. Moved the N variable from the first to the end of the calculation)
Sub Example3()
Dim N As Long, L As Long
N = 15
L = 1000 * 60 * N
MsgBox L
End Sub