Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tim Tim is offline
external usenet poster
 
Posts: 408
Default UDF returning #value

Howdy;

I have the following UDF that keeps returning #value in the worksheet. When
I debug, it appears to bring in the right values, and does the calcs, at
least through the nSecondsPerDay.

Help or guidance would be apprecicated.

Regards
Tim
-----

Function MixVelocity2007(OilRate_mbd As Double, WaterRate_mbd As Double, _
GasRate_mscfd As Double, Pressure_psi As Double, Temperature_F As Double, _
PipeID_in As Double) As Double

Dim nLiquidRate As Double
Dim nGasRate As Double
Dim nTempConversion As Double
Dim nPipeIDArea As Double
Dim nSecondsPerDay As Double

nLiquidRate = (OilRate_mbd + WaterRate_mbd) * 5.6146
nGasRate = GasRate_mscfd * 1000 * (14.7 / Pressure_psi)
nTempConversion = ((Temperature_F - 32) * (5 / 9) + 273.15) / 288.15
nPipeIDArea = (PipeID_in / 12) ^ 2 * 3.1415 / 4
nSecondsPerDay = 60 * 60 * 24

MixVelocity2007 = (nLiquidRate + (nGasRate * nTempConversion)) / _
(nPipeIDArea * nSecondsPerDay)

End Function

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default UDF returning #value

Try changing this one line:
nSecondsPerDay = 60 * 60 * 24
to
nSecondsPerDay = 60# * 60 * 24
or
nSecondsPerDay = 86400
or
nSecondsPerDay = 86400#

60 * 60 * 24 are all integers. Since they're all integers, excel's VBA wants to
use an integer to hold that product (60*60*24). But 86400 is too large to be
held in an integer--and so you get an overflow error.

By using 60#, I've made that 60 a double. So excel's VBA will use a double to
hold that product and everything will (er, should) work ok.



tim wrote:

Howdy;

I have the following UDF that keeps returning #value in the worksheet. When
I debug, it appears to bring in the right values, and does the calcs, at
least through the nSecondsPerDay.

Help or guidance would be apprecicated.

Regards
Tim
-----

Function MixVelocity2007(OilRate_mbd As Double, WaterRate_mbd As Double, _
GasRate_mscfd As Double, Pressure_psi As Double, Temperature_F As Double, _
PipeID_in As Double) As Double

Dim nLiquidRate As Double
Dim nGasRate As Double
Dim nTempConversion As Double
Dim nPipeIDArea As Double
Dim nSecondsPerDay As Double

nLiquidRate = (OilRate_mbd + WaterRate_mbd) * 5.6146
nGasRate = GasRate_mscfd * 1000 * (14.7 / Pressure_psi)
nTempConversion = ((Temperature_F - 32) * (5 / 9) + 273.15) / 288.15
nPipeIDArea = (PipeID_in / 12) ^ 2 * 3.1415 / 4
nSecondsPerDay = 60 * 60 * 24

MixVelocity2007 = (nLiquidRate + (nGasRate * nTempConversion)) / _
(nPipeIDArea * nSecondsPerDay)

End Function


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tim Tim is offline
external usenet poster
 
Posts: 408
Default UDF returning #value

Dave;

Thanks for the tip, works like a charm. I thought the DIM statement for the
variable would have handled it...

Regards,
Tim

"Dave Peterson" wrote:

Try changing this one line:
nSecondsPerDay = 60 * 60 * 24
to
nSecondsPerDay = 60# * 60 * 24
or
nSecondsPerDay = 86400
or
nSecondsPerDay = 86400#

60 * 60 * 24 are all integers. Since they're all integers, excel's VBA wants to
use an integer to hold that product (60*60*24). But 86400 is too large to be
held in an integer--and so you get an overflow error.

By using 60#, I've made that 60 a double. So excel's VBA will use a double to
hold that product and everything will (er, should) work ok.



tim wrote:

Howdy;

I have the following UDF that keeps returning #value in the worksheet. When
I debug, it appears to bring in the right values, and does the calcs, at
least through the nSecondsPerDay.

Help or guidance would be apprecicated.

Regards
Tim
-----

Function MixVelocity2007(OilRate_mbd As Double, WaterRate_mbd As Double, _
GasRate_mscfd As Double, Pressure_psi As Double, Temperature_F As Double, _
PipeID_in As Double) As Double

Dim nLiquidRate As Double
Dim nGasRate As Double
Dim nTempConversion As Double
Dim nPipeIDArea As Double
Dim nSecondsPerDay As Double

nLiquidRate = (OilRate_mbd + WaterRate_mbd) * 5.6146
nGasRate = GasRate_mscfd * 1000 * (14.7 / Pressure_psi)
nTempConversion = ((Temperature_F - 32) * (5 / 9) + 273.15) / 288.15
nPipeIDArea = (PipeID_in / 12) ^ 2 * 3.1415 / 4
nSecondsPerDay = 60 * 60 * 24

MixVelocity2007 = (nLiquidRate + (nGasRate * nTempConversion)) / _
(nPipeIDArea * nSecondsPerDay)

End Function


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default UDF returning #value

But it wasn't the assignment to the left hand side, it was that intermediate
result on the right hand side.

Kind of weird, huh?

tim wrote:

Dave;

Thanks for the tip, works like a charm. I thought the DIM statement for the
variable would have handled it...

Regards,
Tim

"Dave Peterson" wrote:

Try changing this one line:
nSecondsPerDay = 60 * 60 * 24
to
nSecondsPerDay = 60# * 60 * 24
or
nSecondsPerDay = 86400
or
nSecondsPerDay = 86400#

60 * 60 * 24 are all integers. Since they're all integers, excel's VBA wants to
use an integer to hold that product (60*60*24). But 86400 is too large to be
held in an integer--and so you get an overflow error.

By using 60#, I've made that 60 a double. So excel's VBA will use a double to
hold that product and everything will (er, should) work ok.



tim wrote:

Howdy;

I have the following UDF that keeps returning #value in the worksheet. When
I debug, it appears to bring in the right values, and does the calcs, at
least through the nSecondsPerDay.

Help or guidance would be apprecicated.

Regards
Tim
-----

Function MixVelocity2007(OilRate_mbd As Double, WaterRate_mbd As Double, _
GasRate_mscfd As Double, Pressure_psi As Double, Temperature_F As Double, _
PipeID_in As Double) As Double

Dim nLiquidRate As Double
Dim nGasRate As Double
Dim nTempConversion As Double
Dim nPipeIDArea As Double
Dim nSecondsPerDay As Double

nLiquidRate = (OilRate_mbd + WaterRate_mbd) * 5.6146
nGasRate = GasRate_mscfd * 1000 * (14.7 / Pressure_psi)
nTempConversion = ((Temperature_F - 32) * (5 / 9) + 273.15) / 288.15
nPipeIDArea = (PipeID_in / 12) ^ 2 * 3.1415 / 4
nSecondsPerDay = 60 * 60 * 24

MixVelocity2007 = (nLiquidRate + (nGasRate * nTempConversion)) / _
(nPipeIDArea * nSecondsPerDay)

End Function


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 175
Default UDF returning #value

Put all of the constants such as 60 and 24 into proper declared constants -

dim dblMinutesinHour as double = 60

and so on.

This will make the code more readable.

Also, there is no error handler on your UDF - you should add one to ensure
that an error in this function does not cause other problems.


--
http://www.alignment-systems.com


"tim" wrote:

Howdy;

I have the following UDF that keeps returning #value in the worksheet. When
I debug, it appears to bring in the right values, and does the calcs, at
least through the nSecondsPerDay.

Help or guidance would be apprecicated.

Regards
Tim
-----

Function MixVelocity2007(OilRate_mbd As Double, WaterRate_mbd As Double, _
GasRate_mscfd As Double, Pressure_psi As Double, Temperature_F As Double, _
PipeID_in As Double) As Double

Dim nLiquidRate As Double
Dim nGasRate As Double
Dim nTempConversion As Double
Dim nPipeIDArea As Double
Dim nSecondsPerDay As Double

nLiquidRate = (OilRate_mbd + WaterRate_mbd) * 5.6146
nGasRate = GasRate_mscfd * 1000 * (14.7 / Pressure_psi)
nTempConversion = ((Temperature_F - 32) * (5 / 9) + 273.15) / 288.15
nPipeIDArea = (PipeID_in / 12) ^ 2 * 3.1415 / 4
nSecondsPerDay = 60 * 60 * 24

MixVelocity2007 = (nLiquidRate + (nGasRate * nTempConversion)) / _
(nPipeIDArea * nSecondsPerDay)

End Function

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
UDF from Add-In returning #NAME ryan Excel Worksheet Functions 0 March 5th 08 08:35 PM
Returning an age Neil Excel Discussion (Misc queries) 13 September 7th 07 02:22 AM
Looking up a value and returning another Dan Excel Programming 8 August 18th 06 05:15 AM
UDF returning #VALUE! why? Adam Kroger Excel Discussion (Misc queries) 7 December 18th 05 09:43 PM
Need some help returning a value rcarrollct Excel Worksheet Functions 2 July 6th 05 11:36 PM


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