473,779 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Overflow error while coding in Excel

1 New Member
I consistently get an overflow error at the "SOxBenefit s =" (source code below), while coding in a macros from within Excel, Microsoft XP. I've tried the following:

1. setting a variable equal to a number * CLong(#)
2. changing the variable type, as well as making sure all subsequent variables are of the same type. When attempting to use the ULong type, Excel gives me a mismatch error. I found a thread on how to link a windows file, but the "reference" tab is grayed out. Not sure how to link otherwise.
3. commenting out my code and just using the raw numbers, I still get an overload error, but shouldn't because my variable is under 1E9.

any suggestions?

Thanks.


Sub SS2BikeStorage( )
'
' SS2BikeStorage Macro
'
' Keyboard Shortcut: Ctrl+b
'
Range("B15").Se lect
Application.Got o Reference:="SS2 BikeStorage"



Dim FTE 'Number of full-time equivalent employees
Dim NumParkingSpace 'Total Number of Parking Spaces
Dim ParkingArea 'Total parking lot area [s.f.]
Dim DepthExcav 'Depth of required excavation ["]
Dim UnitCostExcav 'cost to excavate per cubic yard
Dim DepthBackfillCo mpact 'Depth to be backfilled and compacted
Dim UnitCostBackfil lCompact 'cost to backfill and compact per cubic yard
Dim DepthAsphalt 'Depth of asphalt ["]
Dim UnitCostAsphalt 'cost of asphalt per ton
Dim UnitCostSealer 'cost of sealer per gallon
Dim CostRack 'cost of bike rack [$]
Dim CostShowerChang ing
Dim CostLandscaping CurbingDrainage
Dim CostImportedFil l
Dim ConstructionCos ts
Dim WaterCosts
Dim SavedUserBenefi ts
Dim EmissionsSaving s

Const AvgMilesPerDay = 15
Const WorkdaysPerYear = 250 '50 * 5

Dim FTEMilesPerYear As Long
FTEMilesPerYear = 250 'AvgMilesPerDay * WorkdaysPerYear

End Sub
Sub Main() 'Main calling program, runs all others
Data 'inputs data
Analysis 'computes costs and benefits
Output 'Displays program output
End Sub


Sub Data()
FTE = Cells(4, 2) '
NumParkingSpace = Cells(5, 2) '
ParkingArea = Cells(6, 2) 'Total parking lot area [s.f.]
DepthExcav = Cells(7, 2) 'Depth of required excavation ["]
UnitCostExcav = Cells(7, 3) 'cost to excavate per cubic yard
DepthBackfillCo mpact = Cells(8, 2) 'Depth to be backfilled and compacted
UnitCostBackfil lCompact = Cells(8, 3) 'cost to backfill and compact per cubic yard
DepthAsphalt = Cells(11, 2) 'Depth of asphalt ["]
UnitCostAsphalt = Cells(11, 3) 'cost of asphalt per ton
UnitCostSealer = Cells(10, 3) 'cost of sealer per gallon
CostRack = Cells(13, 3) 'cost of bike rack [$]
CostShowerChang ing = Cells(14, 3)
CostLandscaping CurbingDrainage = Cells(15, 3)
CostImportedFil l = Cells(16, 3)

End Sub
Sub Analysis()
'internal cost variables

Dim TotalAsphaltCos t ' construction cost of asphalt
Dim TotalSealCost 'construction cost of sealer
Dim SpaceArea 'square footage per parking space including aisles
Dim TotalExcavCost 'total cost of excavation

Const SealerFactor = 0.15 'gallons of sealer/square yard
Const AsphaltUnitWeig ht = 150 '150 lbs/cubic foot

'Construction costs
SpaceArea = 1.533 * 18 * 9 'assuming 18'x9' spaces and 53% aisle area
TotalAsphaltCos t = DepthAsphalt * SpaceArea * AsphaltUnitWeig ht * UnitCostAsphalt / (12 * 2000) '
TotalSealCost = SealerFactor * UnitCostSeal * SpaceArea / 9
TotalExcavCost = (SpaceArea * DepthExcav * UnitCostExcav) + (SpaceArea * DepthBackfillCo mpact * UnitCostBackfil lCompact)

TotalSavedConst ructionCosts = FTE * (TotalAsphaltCo st + TotalSealCost + TotalExcavCost)

ConstructionCos ts = CostRack + CostShowerChang ing + CostLandscaping CurbingDrainage + CostImportedFil l - TotalSavedConst ructionCosts 'interior changing + landscaping/curbing + bike racks
'Operations Costs
'Water
Const ShowersPerDay = 15
Const MinutesPerShowe r = 5
Const GallonsPerMinut e = 2
Const WorkdaysPerYear = 250 '5 * 50
Const GallonsPerCubic Foot = 7.48
Const CostPerCubicFoo t = 0.64
Const PGivenA = 23.88 '(for i=3.4%, n=50)
Dim GallonsPerYear
Dim WaterCosts

'GallonsPerYear = ShowersPerDay * MinutesPerShowe r * GallonsPerMinut e * WorkdaysPerYear
GallonsPerYear = 37500
WaterCosts = GallonsPerYear * CostPerCubicFoo t * PGivenA / GallonsPerCubic Foot

'Pavement resurfacing
Const AsphaltResurfac ingCost = 1.25 'cost/ft^2
SavedResurfacin g = FTE * SpaceArea * AsphaltResurfac ingCost * (0.61 + 0.37)
'Emissions Costs
'CO2
Const CO2EmissionsMil e = 550.4 'average emission rate of CO2 in grams/mi from MEPA GHG Protocol
Const CO2EmissionsTon = 907185 'grams CO2 per ton CO2
Const CO2Cost = 7.5 'average cost of CO2 credits per ton

CO2Benefits = FTEMilesPerYear * CO2EmissionsMil e * CO2Cost / CO2EmissionsTon

'NOx
Const NOxEmissionsMil e = 0.95 'average emission rate of NOx in grams/mi from
Dim NOxEmissionsTon
NOxEmissionsTon = 454 * CLng(2000) 'grams NOx per ton NOx
Const NOxCost = 27704 'average cost of NOx credits per ton

NOxBenefits = (FTEMilesPerYea r * NOxEmissionsMil e * NOxCost) / NOxEmissionsTon

'SOx
Dim SOxEmissionsMil e As Long 'average emission rate of SOx in grams/mi from
SOxEmissionsMil e = 0.95
Dim SOxEmissionsTon As Long
SOxEmissionsTon = 908000 '454 * 2000 grams SOx per ton NOx
Dim SOxCost As Long 'average cost of SOx credits per ton
SOxCost = 12809
Dim SOxBenefits As Long

SOxBenefits = (FTEMilesPerYea r * SOxEmissionsMil e * SOxCost) / SOx2EmissionsTo n

'PM-10
Const PM10EmissionsMi le = 0.0052 'average emission rate of PM10 in grams/mi from
Dim PM10EmissionsTo n
PM10EmissionsTo n = 454 * 200 'grams PM10 per ton PM10
Const PM10Cost = 46148 'average cost of PM10 credits per ton PM10

PM10Benefits = FTEMilesPerYear * PM10EmissionsMi le * PM10Cost / PM10EmissionsTo n

'Total emissions savings
EmissionsSaving s = CO2Benefits + NOxBenefits + PM10Benefits

'Saved User Costs (gas and vehicle maintenance)
Const FedReimbursemen tRate = 0.485

SavedUserBenefi ts = FedReimbursemen tRate * FTEMilesPerYear

End Sub

Sub Output()
Cells(18, 5) = ConstructionCos ts
Cells(19, 5) = WaterCosts
Cells(20, 5) = SavedUserBenefi ts
Cells(21, 5) = EmissionsSaving s
End Sub
Oct 6 '08 #1
1 1810
ubentook
58 New Member
Your method of declaring variables is working against you.
Variables declared within a sub are only usable within that sub.
Variables declared at the top of the module before all subs are public variables that can be used in all subs.

Using "Option Explicit" as the first line in a module generates a msg when you try to use a variable that hasn't been declared. It is good practice to have that line in every module!

A "Long" data type can only contain integers. If you want to use floating point numbers use a "Double" data type.

One of the reasons you are getting an error msg is you appear to be trying to divide by zero in the line...
"SOxBenefit s = (FTEMilesPerYea r * SOxEmissionsMil e * SOxCost) / SOx2EmissionsTo n"
Note that "SOxEmissionsTo n" (variable) is not the same as "SOx2EmissionsT on" (variable).
Using "Option Explicit" would have identified that issue for you.
Oct 6 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
13955
by: middletree | last post by:
For my ASP app which tracks tech support tickets, I have a report which breaks down how much time each ticket spent in a particular status (there are 7 statuses, and I am not trying to find out how much time in the status of Closed) For display purposes, it takes a time value, displays it, and then displays the same value in percentage form. SO if we spent 100 hours on a ticket, and 34 hours were in the status of Coding, then it would say:...
19
3145
by: Jim | last post by:
I have spent the past few weeks designing a database for my company. The problem is I have started running into what I believe are stack overflow problems. There are two tab controls on the form (nested), three list views, one tree control with up to 30,000 nodes, maybe 15 comboboxes (half of which have a large recordset as rowsource), 20 or so buttons and around 30 text boxes (not to mention the images, labels, etc and around 1000 lines...
2
17525
by: Andy Davis | last post by:
Dear Group I am trying to automate process of adding a new record id in my form using the following code when the user clicks the "Add New Record" button. For example if the last record id is "2005001" then I want to increment this by one so that new value is "2005002" and place it in the record id field for the new record on the form. I've tried using the following code but get the message "Overflow" when I run the code. Can't find on...
2
7601
by: steve.turner | last post by:
Hi all, I'm hoping someone can stop me tearing (what's left of) my hair out over this problem... I have a linked Excel file from which I append the data to an empty local Access table. I have a macro which runs a delete query to empty the local table, then the append query to update it with the new info from the spreadsheet.
0
1571
by: Bob | last post by:
I hope somebody can help. I'm linking to an excel spreadsheet with several fields that come across as double. I can query the linked table fine, but when I make a form with the query as the data source I get a "Numeric Overflow Error" as soon as the form opens. Any ideas?
3
2164
by: MLH | last post by:
A wide comma delimited text file import into A97 failed with an overflow error. I'm estimating it to have been no more than 1000 records. 100% of all the fields were quoted strings or ZLS's. What most likely caused the overflow? Might it be upper limit on number of fields in table?
0
1369
by: snowdream1982 | last post by:
Dear all, I hit an error OVERFLOW but when I insert the sql statement below manually in the SQLEditor, it goes well, no errors at all. My coding: SQLInsertTempMf = "INSERT INTO tempmf " & _ "(scn, bl_num,master_ind,cin_num,master_bl,container_no, consignee_code, consignee_name,consignee_addr1, " & _ "consignee_addr2,consignee_addr3,consignee_addr4,shipper_code,shipper_name,...
7
54265
by: LucasLondon | last post by:
Hi, I have the code below that I adapted to loop through each column of data (Columns A to GR) to perform an a calculation based on the data in rows 2 to 31 of each column and place the calculated statistic in row 35 for each column of data. The problem is the code runs fine for the first six columns of data (i.e row 35 for columns A:F get populated with a correctly calculated statistic but code stops running at column G, and generates a...
1
1383
by: Scott M. | last post by:
Many methods return objects when they are called. With Excel these objects are placed in memory and must be destroyed via ReleaseComObject as you have done with your NAR method, but the line: objExcel.Workbooks.Open(Page.MapPath("reports\BLCost.xls")) could be the culprit since the Open method returns a reference to a Workbook object that you haven't assigned a variable to. Since you have no variable to explicitly use to destroy the...
0
9633
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10137
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9928
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8959
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.