Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Dear Excel Gurus,
I have just encountered the strangest error. Is it a bug in Excel VBA compiler? Below statement encountered overflow error (run-time error 6); If (turnoverToday = (150 * 1000)) Then Below statement encounters no error; If (turnoverToday = (150000)) Then Aren't they the same!!?? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Since both 150 and 1000 are integers, excel's VBA will use store the
intermediate result in an integer. And 150*1000=150000 is too big to fit into an integer. You have a few choices: If (TurnOverToday = (CLng(150) * 1000)) Then If (TurnOverToday = 150& * 1000)) Then (& is the type-declaration character for Long) Dim myNum1 as long dim myNum2 as long 'or make them constants mynum1 = 150 mynum2 = 1000 If (TurnOverToday = (mynum1 * mynum2) Then Sing wrote: Dear Excel Gurus, I have just encountered the strangest error. Is it a bug in Excel VBA compiler? Below statement encountered overflow error (run-time error 6); If (turnoverToday = (150 * 1000)) Then Below statement encounters no error; If (turnoverToday = (150000)) Then Aren't they the same!!?? -- Dave Peterson |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Dave: There is a very simple solution
If (turnoverToday = (150# * 1000#)) Then "Dave Peterson" wrote: Since both 150 and 1000 are integers, excel's VBA will use store the intermediate result in an integer. And 150*1000=150000 is too big to fit into an integer. You have a few choices: If (TurnOverToday = (CLng(150) * 1000)) Then If (TurnOverToday = 150& * 1000)) Then (& is the type-declaration character for Long) Dim myNum1 as long dim myNum2 as long 'or make them constants mynum1 = 150 mynum2 = 1000 If (TurnOverToday = (mynum1 * mynum2) Then Sing wrote: Dear Excel Gurus, I have just encountered the strangest error. Is it a bug in Excel VBA compiler? Below statement encountered overflow error (run-time error 6); If (turnoverToday = (150 * 1000)) Then Below statement encounters no error; If (turnoverToday = (150000)) Then Aren't they the same!!?? -- Dave Peterson |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Seems pretty close to:
If (TurnOverToday = 150& * 1000)) Then (& is the type-declaration character for Long) Except # is the type-declaration for Double. And you don't actually need to use them on each of the constants. One is enough. Joel wrote: Dave: There is a very simple solution If (turnoverToday = (150# * 1000#)) Then "Dave Peterson" wrote: Since both 150 and 1000 are integers, excel's VBA will use store the intermediate result in an integer. And 150*1000=150000 is too big to fit into an integer. You have a few choices: If (TurnOverToday = (CLng(150) * 1000)) Then If (TurnOverToday = 150& * 1000)) Then (& is the type-declaration character for Long) Dim myNum1 as long dim myNum2 as long 'or make them constants mynum1 = 150 mynum2 = 1000 If (TurnOverToday = (mynum1 * mynum2) Then Sing wrote: Dear Excel Gurus, I have just encountered the strangest error. Is it a bug in Excel VBA compiler? Below statement encountered overflow error (run-time error 6); If (turnoverToday = (150 * 1000)) Then Below statement encounters no error; If (turnoverToday = (150000)) Then Aren't they the same!!?? -- Dave Peterson -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Error encounter when i try to click a hyperlink in Excel | Excel Discussion (Misc queries) | |||
need some help, encounter run-time error 1004 | Excel Programming | |||
Simple IF statement | Excel Worksheet Functions | |||
R/T Error encounter - Posted originally to functions ng - in error | Excel Programming | |||
Simple code error statement | Excel Programming |