0

I'm using Excel 2010, and I wonder why the below code doesn't work for me? I've got compile error: syntax error.

Sub test()
Dim myStudents(,) As String = _       
   {{"Dick", "Jane", "Tom", "Sam"}, _
   {"Sue", "Bill", "Mary", ""}}    
End Sub

Example link and code :

Sub xyz()
    Dim xyz()()() As Byte
End Sub

This also produced compile error: syntax error when ran.

4
  • 1
    Define "doesn't work". Are you getting an error? Commented Jan 9, 2013 at 13:52
  • I get 'compile error:syntax error' because of 'myStydents(,)' structure Commented Jan 9, 2013 at 13:53
  • 2
    I don't think jagged arrays are available in VBA (VBA <> VB). You will need to use an array of arrays. Commented Jan 9, 2013 at 14:01
  • lol I've missed 'A' in 'VBA' thanks Commented Jan 9, 2013 at 14:06

1 Answer 1

2

This is VB.net syntax. VB.net is not the same as VBA, which is what is used in Excel, etc. To do this in VBA you can do something like:

Public Sub test()
  Dim myStudents() As Variant

  myStudents = Array( _
                 Array("Dick", "Jane", "Tom", "Sam"), _
                 Array("Sue", "Bill", "Mary") _
               )

  Debug.Print myStudents(0)(1) ' Jane
  Debug.Print myStudents(1)(2) ' Mary
End Sub

i.e., We create an array of arrays.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.