0

When I want to populate a public array, it throws this error:

Option Explicit

Public myArray(5) As Variant

Sub addToArray()
    myArray() = Array(1, 1, 0, 0, 1, 1)
End Sub

It gives me a "Compile error: Can't assign to array" error:

enter image description here

Anyone an idea what might went wrong? This is just a short array. I might make it way bigger. Defining each value separately is not what I want.

0

1 Answer 1

1

You need to declare as variant without size (for the array)

Public myArray() As Variant

to be able to use it like

myArray = Array(1, 1, 0, 0, 1, 1)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.