Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 将内存数组中的信息读入excel工作表公式_Arrays_Excel_Vba_Memory_Formula - Fatal编程技术网

Arrays 将内存数组中的信息读入excel工作表公式

Arrays 将内存数组中的信息读入excel工作表公式,arrays,excel,vba,memory,formula,Arrays,Excel,Vba,Memory,Formula,我希望使用存储在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 Ce

我希望使用存储在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
非常感谢您的帮助。

一种方法是从数组中生成字符串


我不确定你是否能这样做。通常情况下,我的电脑会检查,目前有一个巨大的countif过载。但首先要做的是将“单元格(1,2).公式1c1=“=vlookup(RC1,MyArrayStoredInVBaMemory,1,0)”更改为“单元格(1,2).公式1c1=“=vlookup(RC1,”&myarraystoredinvbamery&“,1,0)”,您打算将数据直接用于哪些公式?将数组分配给单元格值可能很方便,因为它工作得很快:
Range(单元格(1,1),单元格(1,9)).value=array(1,2,3,4,5,6,7,8,9)
,然后您可以将公式参数链接到这些单元格。+1,但我会跳过字符串构建,改用Join:
Range(“A1”).formula=“=SUM(&Join(ary),”&>)
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