Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default variable scope question in user-defined function

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

--
Thanks,
Pertti
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 205
Default variable scope question in user-defined function

Pertti,

Change your loop line to:

For x = 2 To RowValue

Best regards

John

"Pertti" 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

--
Thanks,
Pertti



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default variable scope question in user-defined function

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"
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

--
Thanks,
Pertti
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
Question-user defined function ppyxl[_5_] Excel Programming 2 July 11th 06 03:52 PM
Question about variable scope RB Smissaert Excel Programming 0 March 2nd 05 01:15 PM
Variable scope question w/combo-box, 2ND try Tim Coddington Excel Programming 2 December 20th 03 04:07 AM
Variable scope question w/combo-box Tim Coddington Excel Programming 4 December 17th 03 02:38 AM
How to copy worksheets with a user defined variable Greg K Excel Programming 2 August 19th 03 09:47 PM


All times are GMT +1. The time now is 04:19 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"