What you have is (after the missing comma is inserted after "PlayStation 4"
) perfectly valid VBA. However, it creates a 1-dimensional array. If you want similar notation to create a 2-dimensional array, you can create a custom function:
Function Matrix(m As Long, n As Long, ParamArray items()) As Variant
'Creates an mxn matrix where the items() are filled in by row
Dim A As Variant
Dim i As Long, j As Long
ReDim A(1 To m, 1 To n)
For i = 1 To m
For j = 1 To n
A(i, j) = items(n * (i - 1) + j - 1)
Next j
Next i
Matrix = A
End Function
Used like:
Sub test()
Dim fndList As Variant
fndList = Matrix _
(3, 2, _
"PS4", "PlayStation 4", _
"WIN", "Microsoft Windows", _
"SNES", "Super Nintendo Entertainment System" _
)
Range("A1:B3").Value = fndList
End Sub
The array which is created is 1-based rather than 0-based since in Excel VBA 1-based is the default for interacting with ranges. It would obviously be easy enough to tweak the function so that the array returned is 0-based.
Looking a bit more at your actual problem, if your goal is to lookup values like "Microsoft Windows"
from keys like "WIN"
then you can use a Dictionary:
Sub test2()
Dim fndList As Object
Set fndList = CreateObject("Scripting.Dictionary")
fndList.Add "PS4", "PlayStation 4"
fndList.Add "WIN", "Microsoft Windows"
fndList.Add "SNES", "Super Nintendo Entertainment System"
Debug.Print fndList("WIN") 'prints "Microsoft Windows"
End Sub
You could modify the Matrix()
function so that it returns such a dictionary. For example, something like this:
Function Dict(ParamArray pairs()) As Object
'returns a dictionairy where successive pairs of
'items in the pairs array are treated as key-value
'pairs. It is assumed than an even number of items
'are passed
Dim D As Object
Dim i As Long, n As Long
Set D = CreateObject("Scripting.Dictionary")
n = (UBound(pairs) - 1) / 2
For i = 0 To n
D.Add pairs(2 * i), pairs(2 * i + 1)
Next i
Set Dict = D
End Function
Which can be used like:
Sub test3()
Dim fndList As Object
Set fndList = Dict _
( _
"PS4", "PlayStation 4", _
"WIN", "Microsoft Windows", _
"SNES", "Super Nintendo Entertainment System" _
)
Debug.Print fndList("WIN") 'prints "Microsoft Windows"
End Sub