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.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73

1 Answers1

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)
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73