VBA (Excel) Initialize Entire Array without Looping

后端 未结 6 550
有刺的猬
有刺的猬 2020-12-07 16:10

I am fairly new to VBA, so this may be a simple question but here goes.

I would like to initialize an entire array myArray, say of integers, in VBA. I k

6条回答
  •  情书的邮戳
    2020-12-07 17:04

    This function works with variables for size and initial value it combines tbur & Filipe responses.

    Function ArrayIniValue(iSize As Integer, iValue As Integer)
    Dim sIndex As String
    sIndex = "INDEX(Row(1:" & iSize & "),)"
    ArrayIniValue = Evaluate("=Transpose(" & sIndex & "-" & sIndex & "+" & iValue & ")")
    End Function
    

    Called this way:

    myArray = ArrayIniValue(350, 13)
    

提交回复
热议问题