2009-06-19 200 views

回答

1

這似乎爲我

Call rng.Clear 
Dim rngState As Range 
Set rngState = rng.Resize(nRowCount, nColumnCount) 
rngState.FormulaArray = "whatever_array_formula" 
rngState.Calculate 
0

工作,我一直在尋找,但只是我更透徹的版本考慮到陣列已經被填充:

Sub PasteArray(vTheArray As Variant) 
Dim rPasteHere As Range 

With ActiveWorkbook 
    Set rPasteHere = .Sheets("PayRoll").Range("A1").CurrentRegion 'Assign the region to use 
    With rPasteHere 
     .Clear 'Wipe the current region clean 
     Set rPasteHere = .Resize(UBound(vTheArray, 1) + 1, UBound(vTheArray, 2) + 1) 'Resize the region to your input 
     .FormulaArray = vTheArray 'Dump the array into the resized region 
    End With 
End With 
Set rPasteHere = Nothing 'Clean up! 
End Sub 

記住,數組是從零開始,因此.Resize函數中的+1。對於我的應用程序,我自然地對錶名和範圍進行了硬編碼,這取決於個人。