PC Review


Reply
Thread Tools Rate Thread

average and format range

 
 
ctallen23 via OfficeKB.com
Guest
Posts: n/a
 
      26th Jul 2007
Hello.

I'm having a tough time generating code for a simple program to average stock
prices for each stock symbol column and then given the range of dates with
prices, automatically calculate percentages for the stock price returns (p0 -
beginning stock price, p1 - ending stock price). I've listed some code below.
my Sub program calculates percentages and returns, but once I get to the
bottom of the row, i either get 0.000% across the columns or #value. the
rows below do not have stock prices yet. How can I get a program to
calculate prices (log p1/p0) and not return 0.000% or # value in the bottom
rows that do not contain stock prices given the dates? below gives you an
idea.

Prices AAPL ABT AMAT AMGN AMZN BDX
BDK BMY
9/1/2006 76.98 47.4 17.58 71.53 32.12 69.97 78.23
23.92
8/1/2006 67.85 47.54 16.76 68.03 30.83 68.8 72.
25 20.88
7/3/2006 67.96 46.63 15.58 69.71 26.89 65.07 69.18 23.01
6/4/2006 ----- no prices ----

returns = LN(9-1-2006 / 8-1-2006)
8/1/2006 -0.162% 1.933% 7.301% -2.439% 13.673% 5.574%
4.342% -9.714 %
7/3/2006 0.000% 0.000%, etc..... #value


Sub FillRange2()
Dim row As Integer
Dim col As Integer
Dim stockmax As Integer
stockmax = Range("b2")

For row = 0 To 11
For col = 0 To stockmax - 1

If Range("b25") <> vbEmpty Then
Range("b25").Copy ActiveCell.Offset(row, col)

End If

Sheets("Sheet1").Range("b25").Offset(row, col).NumberFormat = "0.000%"
Next col
Next row

End Sub
I would need a stock price for 6/4/2006 to calculate the returns. How can I
get rid of these percetages or # value without having a lower cell without a
price... such as with 6/4/2006?

Any help would be appreciated. Is there a way for the program to determine
on its own the range? Currently I have this set to a 12X12 because errors
occur with anything greater than this.

Thanks. chris

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200707/1

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
average if - between range Chris26 Microsoft Excel Worksheet Functions 2 3rd Jun 2010 12:26 PM
Average last 3 in range Preschool Mike Microsoft Excel Worksheet Functions 13 14th Oct 2009 05:18 PM
Average of range help impius1 Microsoft Excel Programming 6 17th Aug 2006 08:52 PM
Average of a >, < range Deb Pingel Microsoft Excel Worksheet Functions 4 22nd Dec 2005 12:37 AM
Average Range Stndt Microsoft Excel Worksheet Functions 3 27th Oct 2004 10:00 PM


Features
 

Advertising
 

Newsgroups
 


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