2009-06-19 136 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。对于我的应用程序,我自然地对表名和范围进行了硬编码,这取决于个人。