ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   help! function not obtaining cell values (https://www.excelbanter.com/excel-programming/429800-help-function-not-obtaining-cell-values.html)

maweilian

help! function not obtaining cell values
 
Newbie question:

The simple VBA function below is not working. It is called by the following
in the spreadsheet:
=calcsoilpress(D9,D10,'Soil Data'!D7,'Soil Data'!E7,D17)

(note: "Soil Data" is another worksheet in the same xls file)

When I add a breakpoint at the first "If-Then" line and examine the value of
the variables, I discovered that some of the parameters had a value of zero.
But the value of the cells are not zero! What is happening here?

Thanks in advance for any help!

Will

See code below:


Public Function calcsoilpress(soiltop As Double, soilbottom As Double,
soilwtdensitydry As Double, soilwtdensitywet As Double, waterdepth As Double)

If waterdepth <= soiltop Then
calsoilpress = (soilbottom - soiltop) * soilwtdensitywet
End If

If waterdepth = soilbot Then
calsoilpress = (soilbottom - soiltop) * soilwtdensitydry
End If

If waterdepth soiltop And waterdepth < soilbot Then
calsoilpress = ((soilbottom - waterdepth) * soilwtdensitywet) +
((waterdepth - soiltop) * soilwtdensitydry)
End If

End Function


maweilian

help! function not obtaining cell values
 
Thanks so much. Problem solved! I feel pretty silly. Its amazing how your
mind can play tricks on you.

"Bob Umlas" wrote:

The name of the ****ion is calcsoilpress but inside the function you're
referencing calsoilpress -- the names much match exactly -- the "c" is
missing!
"maweilian" wrote in message
...
Newbie question:

The simple VBA function below is not working. It is called by the
following
in the spreadsheet:
=calcsoilpress(D9,D10,'Soil Data'!D7,'Soil Data'!E7,D17)

(note: "Soil Data" is another worksheet in the same xls file)

When I add a breakpoint at the first "If-Then" line and examine the value
of
the variables, I discovered that some of the parameters had a value of
zero.
But the value of the cells are not zero! What is happening here?

Thanks in advance for any help!

Will

See code below:


Public Function calcsoilpress(soiltop As Double, soilbottom As Double,
soilwtdensitydry As Double, soilwtdensitywet As Double, waterdepth As
Double)

If waterdepth <= soiltop Then
calsoilpress = (soilbottom - soiltop) * soilwtdensitywet
End If

If waterdepth = soilbot Then
calsoilpress = (soilbottom - soiltop) * soilwtdensitydry
End If

If waterdepth soiltop And waterdepth < soilbot Then
calsoilpress = ((soilbottom - waterdepth) * soilwtdensitywet) +
((waterdepth - soiltop) * soilwtdensitydry)
End If

End Function





Patrick Molloy

help! function not obtaining cell values
 
placing
OPTION EXPLICIT
at the start of the module will help . under Tools/Options under the Editor
tab, make sure that 'Require Variable Declaration' is checked. This is great
for trapping those typos.
Also, before running code, use the Debug / Compile menu item to do a quick
check in case something obvious is broken


"maweilian" wrote in message
...
Thanks so much. Problem solved! I feel pretty silly. Its amazing how
your
mind can play tricks on you.

"Bob Umlas" wrote:

The name of the ****ion is calcsoilpress but inside the function you're
referencing calsoilpress -- the names much match exactly -- the "c" is
missing!
"maweilian" wrote in message
...
Newbie question:

The simple VBA function below is not working. It is called by the
following
in the spreadsheet:
=calcsoilpress(D9,D10,'Soil Data'!D7,'Soil Data'!E7,D17)

(note: "Soil Data" is another worksheet in the same xls file)

When I add a breakpoint at the first "If-Then" line and examine the
value
of
the variables, I discovered that some of the parameters had a value of
zero.
But the value of the cells are not zero! What is happening here?

Thanks in advance for any help!

Will

See code below:


Public Function calcsoilpress(soiltop As Double, soilbottom As Double,
soilwtdensitydry As Double, soilwtdensitywet As Double, waterdepth As
Double)

If waterdepth <= soiltop Then
calsoilpress = (soilbottom - soiltop) * soilwtdensitywet
End If

If waterdepth = soilbot Then
calsoilpress = (soilbottom - soiltop) * soilwtdensitydry
End If

If waterdepth soiltop And waterdepth < soilbot Then
calsoilpress = ((soilbottom - waterdepth) * soilwtdensitywet) +
((waterdepth - soiltop) * soilwtdensitydry)
End If

End Function






All times are GMT +1. The time now is 09:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com