I have investment returns for stocks that I would like to calculate the mean for based upon a certain date range i.e. 1st May 2010 to 14th May 2010 (daily date to daily date) or January to March (month to month).
The spreadsheet is set up in that Sheet2 has the daily dates in "column A", "column B" has Stock_A daily returns, "column C" has Stock_B daily returns, and "column D" has Stock_C returns.
Sheet1 has user inputs i.e. Stock, StartDate, EndDate, and DataFrequency.
I would like to create a dynamic procedure that would allow the user to pick the stock, enter the start date in question, enter the end date in question, the data frequency in question, and the mean value for that period would appear in Sheet3 in cell A1 for example.
The below is me just thinking about it.
Expand|Select|Wrap|Line Numbers
- Dim Stock As String
- Dim StartDate As Date
- Dim EndDate As Date
- Dim DataFreQ As String
- ' User inputs
- Fund = Worksheets("Sheet1").Range("A1")
- StartDate = Worksheets("Sheet1").Range("A2")
- EndDate = Worksheets("Sheet1").Range("A3")
- DataFrequency = Worksheets("Sheet1").Range("A4")
I’m still learning and definitely not a VBA master yet. Hence, my main question is how do I create procedure that calculates the mean for a certain start date and end date range.
Any assistance would be much appreciated.
Thanks.