Table of Contents

VBC09360 — Can't assign to array

Severity: Error  ·  Family: VBC (static semantics / abstract syntax tree)  ·  Source metadata: VBCompileErrorInfo

An array declared with fixed dimensions is assigned an array, or an array declared without them is assigned a number, a String, a Boolean or a Date.

An array declared with its dimensions is the storage of its elements, which are assigned one at a time. Only an array declared without dimensions (Dim a() As Long) can be assigned another array whole: an array, or a Variant that holds one when the statement runs (a Byte() is assigned a String too, the data it is). A number, a String, a Boolean or a Date is never one.

MS-VBA reports the same error, with the same message (recorded in Excel).

This code is raised by StatementStaticSemanticsEvaluator.

How it is raised

Situation Example Resolution
A fixed-size array assigned. Dim a(2) As Long, b(2) As Long … a = b Declare the target without dimensions, or copy the elements in a loop.
A resizable array assigned a number, a String (unless it is a Byte()), a Boolean or a Date. Dim a() As Variant … a = 5; Dim a() As Long … a = "abc"; ReDim y(2) … y = 5 Assign an element (a(0) = 5), or declare the target a Variant.

See also


⏮️ VBC09359 Invalid Next control variable reference | ⏭️ VBC09361 ByRef argument type mismatch


ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca