Overcoming the 255 char. limit for formulaArray in Excel VBA

前端 未结 2 1718
刺人心
刺人心 2020-12-21 08:18

I need an array to be inserted into a specific cell and I keep running into the 1004 error. Here is the code:

Range(\"o37\").FormulaArray = \"=CONCATENATE(SU         


        
2条回答
  •  情书的邮戳
    2020-12-21 08:54

    Sub SetTooLongArrayFormula(ByVal rn As Range, ByVal sFormula As String)
        Dim sFormat As String
        sFormat = rn.Cells(1, 1).NumberFormat
        rn.FormulaArray = ""
        rn.Cells(1, 1).NumberFormat = "@"
        rn.Value = sFormula
        rn.Cells(1, 1).NumberFormat = sFormat
        rn.Select
        DoEvents
        SendKeys "{F2}", True
        DoEvents
        SendKeys "+^{ENTER}", True
        
    End Sub
    Sub Test()
        'Do not run this macro from VBE Editor
        'Run this macro from the Macros ribbon on the Developer tab with the Excel worksheet in front.
        Dim sFormula As String
        sFormula = "=""1"""
        For i = 1 To 250
            sFormula = sFormula & "&""1"""
        Next
        SetTooLongArrayFormula Range("A1:A2"), sFormula
    End Sub
    

提交回复
热议问题