Syntax of matrix in vba excel

Viewed 104

I'm new to the VBA Excel. The code works in its current state, yet the comment section produces an error. Why?

Option Explicit

Sub Matrix()
Dim x() As Variant: Dim y As Variant
ReDim x(1 To 2, 1 To 2)
y = 7
x = [{5, 13; 3, 8}]
x(1, 1) = y
'x = [{y, 13; 3, 8}]
End Sub
1 Answers

You cant use the Evaluate Brackets with variables, try it like this:

x = Application.Evaluate("{" & y & ", 13; 3, 8}")
Related