variable scope question in user-defined function

P

Pertti

Hello,

I have a piece of code, which is supposed to calculate the value of a series
of payments in a particular time, taking into account the current market
value of the fund.

The variable FundValue does not seem to work however, so nothing appears in
Excel.

Function FundValue(RowValue As Integer, curPrice As Double)

Dim x As Integer
Dim payment, units, price, curValue As Double

curValue = 0
payment = 0
price = 0

For x = 2 To x = RowValue

payment = Cells(x, 6)
price = Cells(x, 3)
units = payment / price

curValue = curValue + units * curPrice

Next x

FundValue = curValue

End Function
 
J

Jim Cone

With a little cleaning up it worked for me...

Function FundValue(RowValue As Integer, curPrice As Double)
Dim x As Integer
Dim payment As Double
Dim units As Double
Dim price As Double
Dim curValue As Double

curValue = 0
payment = 0
price = 0

For x = 2 To RowValue
payment = Cells(x, 6).Value
price = Cells(x, 3).Value
units = payment / price
curValue = curValue + (units * curPrice)
Next x

FundValue = curValue
End Function
------------------
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware




"Pertti" <[email protected]>
wrote in message
Hello,
I have a piece of code, which is supposed to calculate the value of a series
of payments in a particular time, taking into account the current market
value of the fund.
The variable FundValue does not seem to work however, so nothing appears in
Excel.

Function FundValue(RowValue As Integer, curPrice As Double)

Dim x As Integer
Dim payment, units, price, curValue As Double

curValue = 0
payment = 0
price = 0

For x = 2 To x = RowValue

payment = Cells(x, 6)
price = Cells(x, 3)
units = payment / price

curValue = curValue + units * curPrice

Next x

FundValue = curValue
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top