实际上输入范围也大于数组公式所需的实际范围。因此,如果答案还包括在填写数组公式之前调整范围大小的代码,那将是很好的。
答案 0 :(得分:1)
这似乎对我有用
Call rng.Clear
Dim rngState As Range
Set rngState = rng.Resize(nRowCount, nColumnCount)
rngState.FormulaArray = "whatever_array_formula"
rngState.Calculate
答案 1 :(得分: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。对于我的应用程序,我对工作表名称和范围进行了硬编码,以便 rPasteHere 自然而然地取决于个人。