0
我把這個寫在vba的sub中,但是我不知道如何在循環的外面得到 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環路以外。任何幫助將非常感激。
什麼不起作用?既然你在循環開始之前聲明瞭final_array,你應該可以在循環之後很好地訪問它。 – squillman
當我嘗試使用Debug.Print final_array或Application.Transpose(final_array)它不返回任何東西....我打印數組的所有單個元素,所以我知道值在那裏,只是不知道爲什麼我不能轉置它外環 – googlekid