Calling function - problem in calculation

prinzip

New Member
Joined
Feb 7, 2012
Messages
34
Sorry for the stupid question, but it seems the mistake is when I'm trying to call the function for the calculation. I do not do it the proper way i guess, and i get crazy results, or no results. How is the correct way for the below procedure?

Code:
Option Explicit
Dim EFCO2 As Long, CO2em As Long, x1 As Long, x2 As Long

    CO2em = Emissions(x1, x2, EFCO2)
    MsgBox "CO2 emissions = " & CO2em & " t"

Function Emissions(ENcat As Long, Ptech As Long, EFtech As Long)

    Emissions = ENcat * Ptech * EFtech * 10 ^ 6

End Function
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
is all of this integer math? i would consider checking that you have not overflowed or used non-integers anywhere.
 
Upvote 0
is all of this integer math? i would consider checking that you have not overflowed or used non-integers anywhere.

Changed number declaration from Long to Double, didn't change something to the result.

Code:
EFCO2 = Selection.Columns(4).Select MsgBox "CO2 em = " & CO2em & " t"
Message box says that CO2em is -1 while it had to be 71.887, at least that's the highlighten value in the excel spreadsheet.
Don't know why that
 
Upvote 0
you need to step thru the code 1 line at a time and check the values as you go. there is obviously more code than you have posted. use F8 to step.
 
Upvote 0
good pickup. one less to worry about.
 
Upvote 0

Forum statistics

Threads
1,216,211
Messages
6,129,528
Members
449,515
Latest member
lukaderanged

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top