Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default average and format range

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
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
Pivot table Average with [h]:mm format Opa Horst Excel Discussion (Misc queries) 5 December 16th 09 08:31 PM
AVERAGE a range in a column if another column's range equals a val bob$ Excel Discussion (Misc queries) 3 February 24th 09 07:42 AM
how do I average a column in HR:MIN format (4:12) Thomas Excel Worksheet Functions 2 October 16th 08 04:33 PM
How do I average time (in text format) Butterycolor Excel Discussion (Misc queries) 1 June 3rd 08 02:05 AM
Average Time Format Brento Excel Discussion (Misc queries) 2 March 27th 06 11:35 PM


All times are GMT +1. The time now is 08:52 PM.

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"