これを vba のサブに記述しましたが、ループの外でfinal_arrayを取得する方法がわかりません。シートに転置するか、グローバル多次元配列に保存したいと思います。
Dim lent As Long
Dim end_ct As Long
end_ct = 0
Dim final_array() As Variant
ReDim Preserve final_array(11)
final_array(0) = Range("B2").value
final_array(1) = Range("B3").value
j = 8
'Debug.Print final_array(0)
'Debug.Print final_array(1)
For lent = 2 To 11 Step 1
If lent Mod 2 = 0 Then
ReDim Preserve final_array(11)
final_array(lent) = end_pt(end_ct) - strt_pt(end_ct)
end_ct = end_ct + 1
'Sheets("SingleEquityHistoryHedge").Cells(47, lent + 1).value = final_array(lent)
Else
'gets average over pattern period
Dim avg_rng As Range
Set avg_rng = Sheets("SingleEquityHistoryHedge").Range(Cells(strt_pt(end_ct), j), Cells(end_pt(end_ct) - 1, j))
'Debug.Print sum_rng
Dim avg_value As Double
avg_value = avgVal(avg_rng)
ReDim Preserve final_array(11)
final_array(lent) = avg_value
' Sheets("SingleEquityHistoryHedge").Cells(47, lent + 2).FormulaArray = _
' "=AVERAGE(IF(ISNUMBER(" & avg_rng.Address & ")," & avg_rng.Address & "))"
j = j + 1
End If
' Debug.Print final_array(lent)
' Debug.Print final_array
' If lent = 11 Then
' Range("A" & pos).Select
' Application.WorksheetFunction.Transpose (final_array)
' End If
Next lent
私の目標は、ループの外で final_array を出力できるようにすることです。どんな助けでも大歓迎です。