So I don't have much for code to supply that will help you but I'll give you the code anyways.
My problem is just to do with one line -- in the line I'm trying to set a cell equal to the standard deviation of a variable range.
I need the cell to end up being a cell-reference formula so I can copy and paste it to calculate the standard deviation of many different ranges.
Goal:
set the activecell equal to the standard deviation of the range Start (my variable range) to Start.offset(vlookback * 20, 0)
However, it needs to show up in the cell as something like "STDEV(B3:B23)" so when I copy that cell and paste it across the range(B3:G90) it will match the destination formatting.
This is largely just a syntax error, thanks for the help.
These were the two ways I already tried, it's a bit messy -- I'm pretty new to this haha. Thanks again. Let me know if you have any questions.
'ActiveCell.FormulaR1C1 = "=STDEV(R[-" & vlookback & "]C[-" & n & "-1] : RC[-" & n & "-1])"
ActiveCell.Value = "=STDEV(" & start & ": " & start.Offset(vlookback * 20, 0) & ")"
Sub volatility()
Dim start As Range
Dim myEnd As Range
Dim devstart As Range
Dim devend As Range
Dim rankstart As Range
Dim rankend As Range
'DELETE DELETE DELETE
Dim vlookback As Integer
vlookback = 1
Dim rowNum As Integer
rowNum = 61
Dim n As Integer
n = 9
'DELETE DELETE DELETE
'CHANGE worksheet selection back to V!!!
Worksheets("VTest").Activate
'this section generates the daily %Changes
Range("B3").Select
ActiveCell.Value = "=(AssetData!B3 - AssetData!B2) / AssetData!B2"
ActiveCell.Copy
Set start = ActiveCell
ActiveCell.Offset(rowNum - 2, n - 1).Select
Set myEnd = ActiveCell
Range(start, myEnd).PasteSpecial
'this section generates the standard deviation on the requested lookback period
Range("B3").Offset(0, n + 1).Select
ActiveCell.Offset(20 * vlookback, 0).Select
'ActiveCell.FormulaR1C1 = "=STDEV(R[-" & vlookback & "]C[-" & n & "-1] : RC[-" & n & "-1])"
ActiveCell.Value = "=STDEV(" & start & ": " & start.Offset(vlookback * 20, 0) & ")"
ActiveCell.Copy
Set devstart = ActiveCell
Do
ActiveCell.Offset(1, 0).Select
Loop Until IsEmpty(ActiveCell.Offset(1, -2))
ActiveCell.Offset(0, n - 1).Select
Set devend = ActiveCell
Range(devstart, devend).PasteSpecial
'this section ranks the standard deviations
devstart.Offset(0, n + 1).Select
Set rankstart = ActiveCell
ActiveCell.FormulaR1C1 = "=Rank(RC[-n-1], RC[-n-1]:RC[-2], 1)"
ActiveCell.Copy
Set rankend = ActiveCell.Offset(rowNum - 2, n - 1)
Range(rankstart, rankend).PasteSpecial
End Sub
Bookmarks