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

Any know how to fix this overflow error? Cell A1 has a date value of "01/01/2200".

Sub errTest()
Dim d1, currDay As Date
Dim r As Integer

currDay = Date
d1 = Sheet1.Range("A1").Value

r = currDay - d1 - 7 ' Error because A1 = 01/01/2200

msgbox r

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Overflow error


"Tatsujin" wrote in message
Any know how to fix this overflow error? Cell A1 has a date value of
"01/01/2200".

Sub errTest()
Dim d1, currDay As Date
Dim r As Integer

currDay = Date
d1 = Sheet1.Range("A1").Value

r = currDay - d1 - 7 ' Error because A1 = 01/01/2200

msgbox r

End Sub


Various reasons the result will overflow. d1 is undeclared so when returning
a cell value it will change to a Double or Date (or 'Empty' if the cell is
empty, String or Error). You've got r declared as an Integer but Date is
beyond the bounds of and Integer so any calculation with the d1 and currDate
will likely return as a Date. Try this
Dim r as Integer
r = Date

Change the r declaration to Long or if need to be sure working with dates to
As Date. Also declare d1 As Long or As Date as applicable for your purposes.
In passing, except in limited scenarios, normally declaring As Integer
rather than As Long serves no useful purpose. In doesn't save memory or
improve efficiency in +32bit computing.

Unless sure of what the cell will contain more work might be required to
avoid or handle unexpected values resulting in errors or invalid results.

Peter T



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 Bishop Excel Programming 12 June 26th 09 12:49 PM
Overflow Error Bishop Excel Programming 2 June 26th 09 05:12 AM
overflow error Brad Excel Programming 4 April 2nd 09 10:39 PM
Overflow error Jim Berglund Excel Programming 3 January 30th 05 05:57 PM
Help! Overflow Error 6 Gauthier Excel Programming 6 September 24th 04 12:57 PM


All times are GMT +1. The time now is 02:05 AM.

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

About Us

"It's about Microsoft Excel"