从内存数组读取信息到Excel表单公式中

我想从我的VBA内存中存储的数组中直接使用数据到我的工作表中的公式中。 作为一个例子,我想避免使用Application.vlookup()打印到每个单元格,因为这是慢的。 而是做一些如下所示

Sub MySub() Dim MyArrayStoredInVBaMemory() As Variant MyArrayStoredInVBaMemory = Array(1, 2, 3, 4, 5, 6, 7, 8, 9) Cells(1, 1).Value = 1 Cells(1, 2).FormulaR1C1 = "=vlookup(RC1,MyArrayStoredInVBaMemory,1,0)" Cells(1, 2).Copy Cells(1, 2).PasteSpecial xlPasteValues Application.CutCopyMode = False End Sub 

你的帮助表示赞赏。

一种方法是从数组中创build一个string

 Sub qwerty() ary = Array(1, 2, 3) Dim st As String st = ary(0) & "," & ary(1) & "," & ary(2) Range("A1").Formula = "=SUM(" & st & ")" End Sub