1
实际上,输入范围也大于数组公式所需的实际范围。所以如果答案还包括在填入数组公式之前调整范围的代码,那将会很好。如何使用VBA填充Excel工作表中的数组公式并使用VBA填充数组公式?
实际上,输入范围也大于数组公式所需的实际范围。所以如果答案还包括在填入数组公式之前调整范围的代码,那将会很好。如何使用VBA填充Excel工作表中的数组公式并使用VBA填充数组公式?
这似乎为我
Call rng.Clear
Dim rngState As Range
Set rngState = rng.Resize(nRowCount, nColumnCount)
rngState.FormulaArray = "whatever_array_formula"
rngState.Calculate
工作,我一直在寻找,但只是我更透彻的版本考虑到阵列已经被填充:
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。对于我的应用程序,我自然地对表名和范围进行了硬编码,这取决于个人。