1
votes

I would like to know it is possible to set text in static array in the parenthesis like the following code.

Sub test()
          Dim myarray(1 to 10 , Costs to Revenues )
          myarray(1,Costs) = ...
          ...
End sub
2
What do Costs and Revenues represent here? - Tim Williams
Is there an Enum there defining values for Costs and Revenues? - John Alexiou

2 Answers

1
votes

Yes it is possible

Sub Sample()
    Const Costs = 1
    Const Revenues = 2

    Dim myarray(1 To 10, Costs To Revenues)

    myarray(1, Costs) = "Sid"
    myarray(1, Revenues) = "Rout"

    MsgBox myarray(1, Costs)
    MsgBox myarray(1, Revenues)
End Sub
0
votes

AFAIK the only way to use an initializer for an array in VBA is with the Array function. Note that it has to be declared as Variant:

Sub ArrayDemo()

    Dim strings As Variant
    strings = Array("one", "two", "three")

    Dim counter As Integer
    For counter = LBound(strings) To UBound(strings)
        Debug.Print strings(counter)
    Next counter

End Sub