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

I am getting an overflow error with:

Dim StatusBarVariable As Variant
A =1
B = 1

StatusBarVariable = (A * B) / (15000 * 244) * 100

What can I define StatusBarVariable As to not create this error?


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default overflow error

Because all the numeric variables fit in to Integers, VBA
attempts to do the entire calculation with Integers, but
overflows the +/- 32K limitation on 15000*24. Cast one of the
variables as a Long and VBA will do the arithmetic in longs, and
you won't get an overflow error.

StatusBarVariable = (a * b) / (15000& * 244) * 100



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com

"ExcelMonkey " wrote
in message ...
I am getting an overflow error with:

Dim StatusBarVariable As Variant
A =1
B = 1

StatusBarVariable = (A * B) / (15000 * 244) * 100

What can I define StatusBarVariable As to not create this

error?


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default overflow error

Hi Chip I tried this and it still overflows:

Sub NewOne()
Dim A As Long
Dim B As Long
Dim StatusBarVariable As Variant


StatusBarVariable = (A * B) / (15000 * 244) * 100
End Su

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default overflow error

Or sorry should it look like this?

Sub NewOne()
Dim A As Long
Dim B As Long
Dim StatusBarVariable As Variant

A = 1
B = 2


StatusBarVariable = (A * B) / (15000 * 244) * 100
End Sub


---
Message posted from http://www.ExcelForum.com/

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default overflow error

Note that Chip had you convert one of your integers to a long by adding an
ampersand to it:

15000&

You could also use CLng(15000) if you don't like ampersands.

--
Jim Rech
Excel MVP




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default overflow error

Thanks


---
Message posted from http://www.ExcelForum.com/

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default overflow error

If you are interested... Sometimes just rearranging your equation can
prevent Excel from seeing all integers. However, it's best to declare your
variables as others have shown.

Sub NewOne()
Dim A
Dim B
Dim StatusBarVariable

A = 1
B = 2
StatusBarVariable = (A / 15000) * (B / 244) * 100
End Sub


StatusBarVariable = (A * B) / (15000 * 244) * 100


--
Dana DeLouis
Using Windows XP & Office XP
= = = = = = = = = = = = = = = = =


"ExcelMonkey " wrote in message
...
Thanks


---
Message posted from http://www.ExcelForum.com/



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
Overflow error when declaring variables Jeff Excel Discussion (Misc queries) 2 January 9th 08 03:15 PM
Overflow error.. why? Fingerjob Excel Discussion (Misc queries) 4 November 13th 06 05:18 PM
runtime error '6' overflow don Setting up and Configuration of Excel 1 July 26th 05 02:52 AM
Overflow Error DG Excel Discussion (Misc queries) 3 April 15th 05 05:45 PM
Run-time error 6 Overflow FredM Excel Programming 2 January 20th 04 06:05 AM


All times are GMT +1. The time now is 09:39 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"