Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Simple If statement encounter error

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Simple If statement encounter error

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Simple If statement encounter error

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Simple If statement encounter error

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error encounter when i try to click a hyperlink in Excel vic Excel Discussion (Misc queries) 0 December 13th 07 09:04 AM
need some help, encounter run-time error 1004 kiwis Excel Programming 1 June 8th 07 03:58 PM
Simple IF statement Connie Martin Excel Worksheet Functions 0 November 30th 06 05:42 PM
R/T Error encounter - Posted originally to functions ng - in error Jim May Excel Programming 2 December 24th 04 10:43 PM
Simple code error statement Stuart[_5_] Excel Programming 7 March 3rd 04 08:47 PM


All times are GMT +1. The time now is 10:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"